SlideShare a Scribd company logo
1
A Programme Under the Compumitra Series
GridView Control–CS
LAB WORK GUIDE
Data binding is a functionality that allows us to connect data
from a source to a target.
Data Binding in GridView using wizard
 Example Template Creation.
 Database file addition in App_data
 Data Binding with GridView using wizard
 Output
 Code explanation
 Modification Trials
Data Binding in GridView using CS Code
 Example Template Creation.
 Data Binding with GridView using vb code
 Output
 Code explanation
 Modification Trials
 Error Trials
 Practice Exercise
 Learning Summary Review
 References.
OUTLINE
Data Binding
Using GridView control through wizard
Data binding is a general technique that binds
two data/information sources together and
maintains them in sync.
The GridView control enables you to connect to a
data source and display data in tabular format.
GridViewUsingWizardCS: Creating And Renaming Webpage
2. Now Rename this page with "Rename"
option by Right Clicking on "Default.aspx"
1. Select the "Default.aspx" page
in the "Solution Explorer"
3. Rename "Default.aspx"
page to "GridView.aspx" page.
• Follow Standard Website Creation Steps and set your path to
C:Learner<student-id>DataBindingGridViewUsingWizardCS
• Add New Default.aspx page in your Website
1. Select the "Root Path" in the
"Solution Explorer" and Right
Click on it
2. Now select "Add ASP.NET
Folder" option
3. And then select "App_Data"
GridViewUsingWizardCS: Adding App_Data Folder
Adding Database To App_Data
GridViewUsingWizardCS: Adding Database-1
Right Click on "App_Data" and select "Add
Existing Item.." option in Solution Explorer
to attach the database to "App_Data"
For attaching database to your current website follow the
instruction.
GridViewUsingWizardCS: Adding Database-2
1. Select the database you
created
2. Attach the database by
clicking the ‘Add’ Button
Your attached database will
appear in 'App_Data' folder.
To attach the database follow the path "C:Learner<Student-
Id>DatabaseSale".
GridViewUsingWizardCS: Adding Gridview Control
The GridView control enables you to connect to a data source and
display data in tabular format
Drag and Drop "GridView" control
in div From 'Data' Toolbox
Select '<New data source…>' option
from 'Choose Data Source:'
dropdown list of 'GridView Tasks' to
attach a data source in GridView
control.
GridViewUsingWizardCS: Adding AccessDataSource in GridView-1
1. Select "Access
Database" and then
click "OK" button.
2. Click on "Browse" button to
browse for database file
1. Double click on App_Data and select
the database and click "OK" button
Now follow the instructions to select the database
GridViewUsingWizardCS: Adding AccessDataSource in GridView-2
2. Click "Next"
GridViewUsingWizardCS: Adding AccessDataSource in GridView-3
1. Select the table which you
want to access from the
database from DropDown list
If you have applied any query on the tables you can also select
that query from the DropDownList.
Select the fields which You
want to display and click
"Next" button
GridViewUsingWizardCS: Adding AccessDataSource in GridView-4
1. First Click "Test Query" to
test the query
2. Then Click "Finish" button
Test Query is used to test that whether the data is accessed
according to our need or not.
Your tested query will
show here.
GridViewUsingWizardCS: View Of AccessDataSource
'AccessDataSource' control
will automatically appear
here.
Now Run Code By
pressing 'F5'
GridViewUsingWizardCS: Output
Output on browser
Content of the ItemMaster table
will display in GridView
GridViewUsingWizardCS: Source Code Explanation -1
"AutoGenerateColumn" is
used to generate bound
fields automatically.
This source code describes your attached database
and select query
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ItemId" DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="ItemId" HeaderText="ItemId" InsertVisible="False"
ReadOnly="True" SortExpression="ItemId" />
<asp:BoundField DataField="Item_name" HeaderText="Item_name"
SortExpression="Item_name" />
<asp:BoundField DataField="unit" HeaderText="unit" SortExpression="unit" />
<asp:BoundField DataField="Product_Rate" HeaderText="Product_Rate"
SortExpression="Product_Rate" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/sale.mdb" SelectCommand="SELECT * FROM [ItemMaster]">
</asp:AccessDataSource>
"DataKeyNames" defines
Primary key in the table
"DataSourceID" defines
data source as
"AccessdataSource1"
GridViewUsingWizardCS: Source Code Explanation -2
"DataField" Displays name
of the field
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ItemId" DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="ItemId" HeaderText="ItemId" InsertVisible="False"
ReadOnly="True" SortExpression="ItemId" />
<asp:BoundField DataField="Item_name" HeaderText="Item_name"
SortExpression="Item_name" />
<asp:BoundField DataField="unit" HeaderText="unit" SortExpression="unit" />
<asp:BoundField DataField="Product_Rate" HeaderText="Product_Rate"
SortExpression="Product_Rate" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/sale.mdb" SelectCommand="SELECT * FROM [ItemMaster]">
</asp:AccessDataSource>
"BoundField" is to define
different fields in the
GridView.
"SortExpression" Defines
name of the field on which
sorting can be performed
"HeaderText" shows Header
name of the column
GridViewUsingWizardCS: Modification trials
 Select "All Fields" query instead of "ItemMaster" and observe
the difference.
You will see that you are getting the data from all the
tables.
 Instead of selecting ‘*’ while selecting columns select any three
column and see the difference.
Now you can observe from the result that only selected fields
are showing.
 Change the Header Text of column "Item_name" from
"Item_name" to "Product Name" and see the difference after
running the page.
You will see that Header of column is changed.
Data Binding
Using GridView control through CS Code
Data binding provides a simple and consistent
way for applications to present and interact
with data.
The GridView control enables you to connect to
a data source and display data in tabular
format.
GridViewUsingCSCode: .aspx File Creation
1. Drag and Drop a 'Button' control
in div from Standard Toolbox
• Follow Standard Website Creation Steps and set your path to
"C:Learner<student-id>DataBindingGridViewUsingCSCode"
• Add New Default.aspx page in your Website
2. Introduce a new line and Drag and Drop
a 'GridView' control from Data Toolbox
•Add the 'App_Data' folder
•To add the database, follow the path "C:Learner<Student-
Id>DatabaseSale".
GridViewUsingCSCode: Adding Database
1. Add 'App_Data' folder
2. And Database 'Sale.mdb' in
App_Data like previous exercise.
GridViewUsingCSCode: Copy/Paste Code
using System.Data;
using System.Data.OleDb;
Type this code above "Partial
Class _Default"
Go to Default.aspx.cs page
GridViewUsingCSCode: Button1_Click Event handler Code
string conString =@"Provider=Microsoft.JET.OLEDB.4.0;"
+ @"data source= " + Server.MapPath("~/App_Data/sale.mdb");
OleDbConnection conn = new OleDbConnection(conString);
conn.Open();
OleDbCommand aCommand = new OleDbCommand("select * from ItemMaster",
conn);
OleDbDataReader aReader = aCommand.ExecuteReader();
GridView1.DataSource = aReader;
GridView1.DataBind();
conn.Close();
• Generate the Button1_Click handler in the CS code by double-clicking
over the button control of aspx file.
Copy/Paste or Type this code in Button1_Click Event
Handler and run the code with "F5"
GridViewUsingCSCode: Run GridView Page
First click the button
Result will show here.
When you will run your page then after clicking button you will get the output
GridViewUsingCSCode: Code Explanation-1
string conString =@"Provider=Microsoft.JET.OLEDB.4.0;"+ @"data
source= "; Server.MapPath("~/App_Data/sale.mdb");
OleDbConnection conn = new OleDbConnection(conString);
conn.Open();
Opening Connection with
‘Open()’ method
This string type argument is passed, when
we create a connection with MS Access
This statement creates an object
of OleDbConnection class.
This is a path of Database.
using System.Data;
using System.Data.OleDb;
Includes classes which lets us handle
data from data sources
Includes classes that provide
OleDb.Net provider
GridViewUsingCSCode: Code Explanation-2
OleDbCommand aCommand = new OleDbCommand("select *
from ItemMaster", conn);
OleDbDataReader aReader = aCommand.ExecuteReader();
GridView1.DataSource = aReader;
GridView1.DataBind();
conn.Close();
Define the DataSource ID of
GridView equal to DataReader
This statement execute the SQL
query and store its result in
OleDbDataReader class object
This statement creates an object
of OleDbConnection class. This
needs two argument, 1- SQL
Query, 2- OleDbConnection class
object
DataBinding in GridView
Closing Connection
GridViewUsingCSCode: Modification Trails-1
 In SELECT statement, replace '*' sign with 'ItemId,
Item_name'
Run and watch the effect
Now you can observe from the result that only
selected fields have been displayed.
 Add 'As Product_Name' just after the 'Item_name'
SELECT statement.
Syntax: <Field Name> As <New Name>
You will see that Header of column will change
when you will run the page.
GridViewUsingCSCode: Modification Trails-2
 Click on 'Auto Format…' link in 'GridView
Task' and select the 'scheme' equal to 'Black
& Blue 2'
Run and watch the effect
GridViewUsingCSCode: Error Trails
 Remove the Namespace files which we have inserted in the
beginning.
You will get the error as given below
BC30002: Type 'OleDbConnection' is not defined.
 Remove the line dbconn.open() and see the result after
running the page.
The error will be shown that is given below.
ExecuteReader requires an open and available
Connection. The connection's current state is closed.
To remove this error connection should be open.
GridViewUsingCSCode: Practice Exercise
Create a website named Expenses
Add the Database 'Monthly Expenses'
Show column "CatId" and "Description"
from table "Expense Category" and "Date"
and "Detail" from table "Expenses" in a
Grid view using wizard option.
Show column "CatId" and "Description"
from the "Expense Category" table and
"Date" and "Detail" from the "Expenses"
table in a Grid view using code.
GridViewUsingCSCode: Learning Summary Review
Use of GridView control
Adding database to App_Data.
Linking of MS Access database with Grid View
through wizard.
Linking of MS Access database with Grid View
through Code.
Use of OleDb classes.
Bibliography
http://msdn.microsoft.com/en-
us/library/fbk67b6z.aspx
http://www.w3Schools.com
http://www.switchonthecode.com/tutorials/csharp-
tutorial-binding-a-datagridview-to-a-database
http://www.codeproject.com/KB/aspnet/DataGridVi
ew__GridView.aspx
http://www.codersource.net/asp-net/asp-net-2-
0/grid-view-control-in-asp-net-2-0.aspx
Ask and guide me at
sunmitraeducation@gmail.com
Share this information with as many people as
possible.
Keep visiting www.sunmitra.com for
programme updates.
Ad

More Related Content

What's hot (20)

ASP.NET Lecture 4
ASP.NET Lecture 4ASP.NET Lecture 4
ASP.NET Lecture 4
Julie Iskander
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
Madhuri Kavade
 
Data Binding
Data BindingData Binding
Data Binding
LAY Leangsros
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
Snehal Harawande
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Wani Zahoor
 
Disconnected data
Disconnected dataDisconnected data
Disconnected data
aspnet123
 
Ado.net
Ado.netAdo.net
Ado.net
Iblesoft
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
Anekwong Yoddumnern
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
Madhuri Kavade
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
Ngeam Soly
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
DrSonali Vyas
 
Configuring Data Binding part2 ABTO Software Lecture Korotchyn
Configuring Data Binding part2 ABTO Software Lecture KorotchynConfiguring Data Binding part2 ABTO Software Lecture Korotchyn
Configuring Data Binding part2 ABTO Software Lecture Korotchyn
ABTO Software
 
ADO CONTROLS - Database usage
ADO CONTROLS - Database usageADO CONTROLS - Database usage
ADO CONTROLS - Database usage
Muralidharan Radhakrishnan
 
Configuring Data Binding part1 ABTO Software Lecture Korotchyn
Configuring Data Binding part1 ABTO Software Lecture KorotchynConfiguring Data Binding part1 ABTO Software Lecture Korotchyn
Configuring Data Binding part1 ABTO Software Lecture Korotchyn
ABTO Software
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
iFour Institute - Sustainable Learning
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
prabhu rajendran
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
application developer
 
Mvc acchitecture
Mvc acchitectureMvc acchitecture
Mvc acchitecture
laxmi.katkar
 
Ado.net
Ado.netAdo.net
Ado.net
Om Prakash
 

Similar to Grid View Control CS (20)

Grid view control
Grid view controlGrid view control
Grid view control
Paneliya Prince
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
application developer
 
data binding.docx
data binding.docxdata binding.docx
data binding.docx
kishorebabu123
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
Mitchinson
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
Sisir Ghosh
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry university
lhkslkdh89009
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
Aravindharamanan S
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
Vj NiroSh
 
the .NET Framework. It provides the claf
the .NET Framework. It provides the clafthe .NET Framework. It provides the claf
the .NET Framework. It provides the claf
TesfahunMaru1
 
07 asp.net session10
07 asp.net session1007 asp.net session10
07 asp.net session10
Mani Chaubey
 
76.pptx ajx ppt file for univercity of granted
76.pptx ajx ppt file for univercity of granted76.pptx ajx ppt file for univercity of granted
76.pptx ajx ppt file for univercity of granted
hectortrading693
 
IntoTheNebulaArticle.pdf
IntoTheNebulaArticle.pdfIntoTheNebulaArticle.pdf
IntoTheNebulaArticle.pdf
David Harrison
 
IntoTheNebulaArticle.pdf
IntoTheNebulaArticle.pdfIntoTheNebulaArticle.pdf
IntoTheNebulaArticle.pdf
David Harrison
 
Chapter12 (1)
Chapter12 (1)Chapter12 (1)
Chapter12 (1)
Rajalaxmi Pattanaik
 
07 asp.net session10
07 asp.net session1007 asp.net session10
07 asp.net session10
Vivek Singh Chandel
 
Mvc4 crud operations.-kemuning senja
Mvc4 crud operations.-kemuning senjaMvc4 crud operations.-kemuning senja
Mvc4 crud operations.-kemuning senja
alifha12
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08
Mani Chaubey
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08
Vivek Singh Chandel
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
Mitchinson
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
Sisir Ghosh
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry university
lhkslkdh89009
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
Vj NiroSh
 
the .NET Framework. It provides the claf
the .NET Framework. It provides the clafthe .NET Framework. It provides the claf
the .NET Framework. It provides the claf
TesfahunMaru1
 
07 asp.net session10
07 asp.net session1007 asp.net session10
07 asp.net session10
Mani Chaubey
 
76.pptx ajx ppt file for univercity of granted
76.pptx ajx ppt file for univercity of granted76.pptx ajx ppt file for univercity of granted
76.pptx ajx ppt file for univercity of granted
hectortrading693
 
IntoTheNebulaArticle.pdf
IntoTheNebulaArticle.pdfIntoTheNebulaArticle.pdf
IntoTheNebulaArticle.pdf
David Harrison
 
IntoTheNebulaArticle.pdf
IntoTheNebulaArticle.pdfIntoTheNebulaArticle.pdf
IntoTheNebulaArticle.pdf
David Harrison
 
Mvc4 crud operations.-kemuning senja
Mvc4 crud operations.-kemuning senjaMvc4 crud operations.-kemuning senja
Mvc4 crud operations.-kemuning senja
alifha12
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08
Mani Chaubey
 
Ad

More from sunmitraeducation (20)

Java Introduction
Java IntroductionJava Introduction
Java Introduction
sunmitraeducation
 
Installing JDK and first java program
Installing JDK and first java programInstalling JDK and first java program
Installing JDK and first java program
sunmitraeducation
 
Project1 VB
Project1 VBProject1 VB
Project1 VB
sunmitraeducation
 
Project1 CS
Project1 CSProject1 CS
Project1 CS
sunmitraeducation
 
Ms Access
Ms AccessMs Access
Ms Access
sunmitraeducation
 
Database Basics Theory
Database Basics TheoryDatabase Basics Theory
Database Basics Theory
sunmitraeducation
 
Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3
sunmitraeducation
 
Visual Web Developer and Web Controls CS set 3
Visual Web Developer and Web Controls CS set 3Visual Web Developer and Web Controls CS set 3
Visual Web Developer and Web Controls CS set 3
sunmitraeducation
 
Progamming Primer Polymorphism (Method Overloading) VB
Progamming Primer Polymorphism (Method Overloading) VBProgamming Primer Polymorphism (Method Overloading) VB
Progamming Primer Polymorphism (Method Overloading) VB
sunmitraeducation
 
Programming Primer EncapsulationVB
Programming Primer EncapsulationVBProgramming Primer EncapsulationVB
Programming Primer EncapsulationVB
sunmitraeducation
 
Programming Primer Encapsulation CS
Programming Primer Encapsulation CSProgramming Primer Encapsulation CS
Programming Primer Encapsulation CS
sunmitraeducation
 
Programming Primer Inheritance VB
Programming Primer Inheritance VBProgramming Primer Inheritance VB
Programming Primer Inheritance VB
sunmitraeducation
 
Programming Primer Inheritance CS
Programming Primer Inheritance CSProgramming Primer Inheritance CS
Programming Primer Inheritance CS
sunmitraeducation
 
ProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPSProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPS
sunmitraeducation
 
Web Server Controls VB Set 1
Web Server Controls VB Set 1Web Server Controls VB Set 1
Web Server Controls VB Set 1
sunmitraeducation
 
Web Server Controls CS Set
Web Server Controls CS Set Web Server Controls CS Set
Web Server Controls CS Set
sunmitraeducation
 
Web Controls Set-1
Web Controls Set-1Web Controls Set-1
Web Controls Set-1
sunmitraeducation
 
Understanding IDEs
Understanding IDEsUnderstanding IDEs
Understanding IDEs
sunmitraeducation
 
Html Server Image Control VB
Html Server Image Control VBHtml Server Image Control VB
Html Server Image Control VB
sunmitraeducation
 
Html Server Image Control CS
Html Server Image Control CSHtml Server Image Control CS
Html Server Image Control CS
sunmitraeducation
 
Ad

Recently uploaded (20)

Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 

Grid View Control CS

  • 1. 1 A Programme Under the Compumitra Series GridView Control–CS LAB WORK GUIDE Data binding is a functionality that allows us to connect data from a source to a target.
  • 2. Data Binding in GridView using wizard  Example Template Creation.  Database file addition in App_data  Data Binding with GridView using wizard  Output  Code explanation  Modification Trials Data Binding in GridView using CS Code  Example Template Creation.  Data Binding with GridView using vb code  Output  Code explanation  Modification Trials  Error Trials  Practice Exercise  Learning Summary Review  References. OUTLINE
  • 3. Data Binding Using GridView control through wizard Data binding is a general technique that binds two data/information sources together and maintains them in sync. The GridView control enables you to connect to a data source and display data in tabular format.
  • 4. GridViewUsingWizardCS: Creating And Renaming Webpage 2. Now Rename this page with "Rename" option by Right Clicking on "Default.aspx" 1. Select the "Default.aspx" page in the "Solution Explorer" 3. Rename "Default.aspx" page to "GridView.aspx" page. • Follow Standard Website Creation Steps and set your path to C:Learner<student-id>DataBindingGridViewUsingWizardCS • Add New Default.aspx page in your Website
  • 5. 1. Select the "Root Path" in the "Solution Explorer" and Right Click on it 2. Now select "Add ASP.NET Folder" option 3. And then select "App_Data" GridViewUsingWizardCS: Adding App_Data Folder
  • 7. GridViewUsingWizardCS: Adding Database-1 Right Click on "App_Data" and select "Add Existing Item.." option in Solution Explorer to attach the database to "App_Data" For attaching database to your current website follow the instruction.
  • 8. GridViewUsingWizardCS: Adding Database-2 1. Select the database you created 2. Attach the database by clicking the ‘Add’ Button Your attached database will appear in 'App_Data' folder. To attach the database follow the path "C:Learner<Student- Id>DatabaseSale".
  • 9. GridViewUsingWizardCS: Adding Gridview Control The GridView control enables you to connect to a data source and display data in tabular format Drag and Drop "GridView" control in div From 'Data' Toolbox Select '<New data source…>' option from 'Choose Data Source:' dropdown list of 'GridView Tasks' to attach a data source in GridView control.
  • 10. GridViewUsingWizardCS: Adding AccessDataSource in GridView-1 1. Select "Access Database" and then click "OK" button. 2. Click on "Browse" button to browse for database file
  • 11. 1. Double click on App_Data and select the database and click "OK" button Now follow the instructions to select the database GridViewUsingWizardCS: Adding AccessDataSource in GridView-2 2. Click "Next"
  • 12. GridViewUsingWizardCS: Adding AccessDataSource in GridView-3 1. Select the table which you want to access from the database from DropDown list If you have applied any query on the tables you can also select that query from the DropDownList. Select the fields which You want to display and click "Next" button
  • 13. GridViewUsingWizardCS: Adding AccessDataSource in GridView-4 1. First Click "Test Query" to test the query 2. Then Click "Finish" button Test Query is used to test that whether the data is accessed according to our need or not. Your tested query will show here.
  • 14. GridViewUsingWizardCS: View Of AccessDataSource 'AccessDataSource' control will automatically appear here. Now Run Code By pressing 'F5'
  • 15. GridViewUsingWizardCS: Output Output on browser Content of the ItemMaster table will display in GridView
  • 16. GridViewUsingWizardCS: Source Code Explanation -1 "AutoGenerateColumn" is used to generate bound fields automatically. This source code describes your attached database and select query <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ItemId" DataSourceID="AccessDataSource1"> <Columns> <asp:BoundField DataField="ItemId" HeaderText="ItemId" InsertVisible="False" ReadOnly="True" SortExpression="ItemId" /> <asp:BoundField DataField="Item_name" HeaderText="Item_name" SortExpression="Item_name" /> <asp:BoundField DataField="unit" HeaderText="unit" SortExpression="unit" /> <asp:BoundField DataField="Product_Rate" HeaderText="Product_Rate" SortExpression="Product_Rate" /> </Columns> </asp:GridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/sale.mdb" SelectCommand="SELECT * FROM [ItemMaster]"> </asp:AccessDataSource> "DataKeyNames" defines Primary key in the table "DataSourceID" defines data source as "AccessdataSource1"
  • 17. GridViewUsingWizardCS: Source Code Explanation -2 "DataField" Displays name of the field <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ItemId" DataSourceID="AccessDataSource1"> <Columns> <asp:BoundField DataField="ItemId" HeaderText="ItemId" InsertVisible="False" ReadOnly="True" SortExpression="ItemId" /> <asp:BoundField DataField="Item_name" HeaderText="Item_name" SortExpression="Item_name" /> <asp:BoundField DataField="unit" HeaderText="unit" SortExpression="unit" /> <asp:BoundField DataField="Product_Rate" HeaderText="Product_Rate" SortExpression="Product_Rate" /> </Columns> </asp:GridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/sale.mdb" SelectCommand="SELECT * FROM [ItemMaster]"> </asp:AccessDataSource> "BoundField" is to define different fields in the GridView. "SortExpression" Defines name of the field on which sorting can be performed "HeaderText" shows Header name of the column
  • 18. GridViewUsingWizardCS: Modification trials  Select "All Fields" query instead of "ItemMaster" and observe the difference. You will see that you are getting the data from all the tables.  Instead of selecting ‘*’ while selecting columns select any three column and see the difference. Now you can observe from the result that only selected fields are showing.  Change the Header Text of column "Item_name" from "Item_name" to "Product Name" and see the difference after running the page. You will see that Header of column is changed.
  • 19. Data Binding Using GridView control through CS Code Data binding provides a simple and consistent way for applications to present and interact with data. The GridView control enables you to connect to a data source and display data in tabular format.
  • 20. GridViewUsingCSCode: .aspx File Creation 1. Drag and Drop a 'Button' control in div from Standard Toolbox • Follow Standard Website Creation Steps and set your path to "C:Learner<student-id>DataBindingGridViewUsingCSCode" • Add New Default.aspx page in your Website 2. Introduce a new line and Drag and Drop a 'GridView' control from Data Toolbox
  • 21. •Add the 'App_Data' folder •To add the database, follow the path "C:Learner<Student- Id>DatabaseSale". GridViewUsingCSCode: Adding Database 1. Add 'App_Data' folder 2. And Database 'Sale.mdb' in App_Data like previous exercise.
  • 22. GridViewUsingCSCode: Copy/Paste Code using System.Data; using System.Data.OleDb; Type this code above "Partial Class _Default" Go to Default.aspx.cs page
  • 23. GridViewUsingCSCode: Button1_Click Event handler Code string conString =@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source= " + Server.MapPath("~/App_Data/sale.mdb"); OleDbConnection conn = new OleDbConnection(conString); conn.Open(); OleDbCommand aCommand = new OleDbCommand("select * from ItemMaster", conn); OleDbDataReader aReader = aCommand.ExecuteReader(); GridView1.DataSource = aReader; GridView1.DataBind(); conn.Close(); • Generate the Button1_Click handler in the CS code by double-clicking over the button control of aspx file. Copy/Paste or Type this code in Button1_Click Event Handler and run the code with "F5"
  • 24. GridViewUsingCSCode: Run GridView Page First click the button Result will show here. When you will run your page then after clicking button you will get the output
  • 25. GridViewUsingCSCode: Code Explanation-1 string conString =@"Provider=Microsoft.JET.OLEDB.4.0;"+ @"data source= "; Server.MapPath("~/App_Data/sale.mdb"); OleDbConnection conn = new OleDbConnection(conString); conn.Open(); Opening Connection with ‘Open()’ method This string type argument is passed, when we create a connection with MS Access This statement creates an object of OleDbConnection class. This is a path of Database. using System.Data; using System.Data.OleDb; Includes classes which lets us handle data from data sources Includes classes that provide OleDb.Net provider
  • 26. GridViewUsingCSCode: Code Explanation-2 OleDbCommand aCommand = new OleDbCommand("select * from ItemMaster", conn); OleDbDataReader aReader = aCommand.ExecuteReader(); GridView1.DataSource = aReader; GridView1.DataBind(); conn.Close(); Define the DataSource ID of GridView equal to DataReader This statement execute the SQL query and store its result in OleDbDataReader class object This statement creates an object of OleDbConnection class. This needs two argument, 1- SQL Query, 2- OleDbConnection class object DataBinding in GridView Closing Connection
  • 27. GridViewUsingCSCode: Modification Trails-1  In SELECT statement, replace '*' sign with 'ItemId, Item_name' Run and watch the effect Now you can observe from the result that only selected fields have been displayed.  Add 'As Product_Name' just after the 'Item_name' SELECT statement. Syntax: <Field Name> As <New Name> You will see that Header of column will change when you will run the page.
  • 28. GridViewUsingCSCode: Modification Trails-2  Click on 'Auto Format…' link in 'GridView Task' and select the 'scheme' equal to 'Black & Blue 2' Run and watch the effect
  • 29. GridViewUsingCSCode: Error Trails  Remove the Namespace files which we have inserted in the beginning. You will get the error as given below BC30002: Type 'OleDbConnection' is not defined.  Remove the line dbconn.open() and see the result after running the page. The error will be shown that is given below. ExecuteReader requires an open and available Connection. The connection's current state is closed. To remove this error connection should be open.
  • 30. GridViewUsingCSCode: Practice Exercise Create a website named Expenses Add the Database 'Monthly Expenses' Show column "CatId" and "Description" from table "Expense Category" and "Date" and "Detail" from table "Expenses" in a Grid view using wizard option. Show column "CatId" and "Description" from the "Expense Category" table and "Date" and "Detail" from the "Expenses" table in a Grid view using code.
  • 31. GridViewUsingCSCode: Learning Summary Review Use of GridView control Adding database to App_Data. Linking of MS Access database with Grid View through wizard. Linking of MS Access database with Grid View through Code. Use of OleDb classes.
  • 33. Ask and guide me at [email protected] Share this information with as many people as possible. Keep visiting www.sunmitra.com for programme updates.