DataBinding a GridView control
DataBinding is done to attach data coming from a Sql server database or from a custom object to a GridView control. To bind data from the Sql server database, we use the SqlDataSource control and to bind data from custom object, we use the ObjectDataSouce control.There are two ways of DataBinding a GridView control. One is Declarative databinding and the other is programmatic databinding. In Declarative databinding, we use DataSourceID property to bind the GridView control to a DataSource control. In Programmatic databinding, we use DataSource property and DataBind() method to bind the GridView control.
In Declarative Databinding, operations such as selecting and updating are done automatically. When we adopt Programmatic Databinding, GridView will not be able to perform these functions automatically. These functions have to be performed programmatically.
The example below shows how to declaratively databind a GridView control.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$Connectionstrings:ERPConnectionString%>" SelectCommand="SELECT * FROM AccountsTable"> </asp:SqlDataSource> <asp:GridView ID="GridView1" DataSourceID="SqlDataSource1" AutoGenerateColumns="true" runat="server"> </asp:GridView>
GridView Articles
- GridView AutoGenerateColumns property
- Bind GridView control with SqlDataSource control
- Binding a GridView programmatically with dataset
- Binding a GridView programmatically with Generic List Collection
- Using fields with the GridView control
- Adding Boundfields to a GridView control
- Adding button fields to a GridView control
- Create Templatefields in a GridView control
- Access a value using SelectedIndexChanged() event when a row in a GridView is selected
- How to restrict an item from being selected using GridView SelectedIndexChanging Event
- How to add a new row in the GridView control by using the GridView footer template
- Gridview datakeynames
- How to select a particular row in a GridView control using SelectedDataKey method
- Formatting GridView control with CSS
- GridView rowDataBound event
Become an Expert
Learn More
Q1. What is Azure Platform?
GridView CommandField example
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Query entity data model using linq to entities
Difference between arraylist and list collection
How to create a Web service using Visual Studio.net
FormView DataBound Event
Calling base class constructor in C#
Convert a sequence to a generic list using ToList()method
ERP Software Development
Project ideas for students
Accounting Software
Creating an ASP.Net MVC 3 application
Using assemblies in .net applications
How to implement form validation using ASP.Net 2.0 Validation Controls
Constructors in Visual Basic.Net
GridView CommandField example
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Query entity data model using linq to entities
Difference between arraylist and list collection
How to create a Web service using Visual Studio.net
FormView DataBound Event
Calling base class constructor in C#
Convert a sequence to a generic list using ToList()method
ERP Software Development
Project ideas for students
Accounting Software
Creating an ASP.Net MVC 3 application
Using assemblies in .net applications
How to implement form validation using ASP.Net 2.0 Validation Controls
Constructors in Visual Basic.Net