In this section, we learn about ASP.NET datagrid tool.
The DataGrid Web server control is a multi-column, data-bound grid.
The DataGrid control displays the fields of a data source as columns in a table.
Each row in the control represents a record in the data source.
The control supports selection, editing, deleting, paging, and sorting.
Like the Repeater and DataList controls, it enables to format and display records from a database table.
However, it has several advanced features, such as support for sorting and paging through records, which makes it unique.
Let's examine a DataGrid example that retrieves data from a database.
This example uses the database as the data source to display data to the DataGrid. This example includes the following steps.
Create a new form DataGridExample to drag DataGrid upon it.
After adding, now, open toolbox and drag DataGrid control to the form.
After dragging, initially it looks like this figure.
This form contains the following source code at backend.
In the CodeBehind file, we have code of database connectivity, and binding fetched record to the DataGrid.
The front-page codes of our DataGridExample.aspx example are as follows.
A student table contains records that we want to display by using the DataGrid. This table contains this example records.
CodeBehind File
CodeBehind file content:
This code is written to the Page_Load function in DataGridExample.aspx.cs.
How about the Output Screen?
After executing this application, it fetches records from the SQL server and displays to the web browser as you see on the screen.
video txt