WebDataGrid™ allows many features to be enabled for complex behaviors and dynamic operations. The most common use however, is to display data. Binding and displaying data with WebDataGrid is a simple process.
You will learn how to add WebDataGrid to your page, retrieving customers table of the Northwind database.
Create an ASP.NET web page.
Drag a ScriptManager component from the Microsoft® Visual Studio™ toolbox onto the page.
Drag a WebDataGrid control onto the page.
Drag a SqlDataSource component onto the page.
Click the smart tag of the SqlDataSource component and select Configure Data Source. The Configure Data Source configuration wizard appears.
Click New Connection to configure the connection string. The Add Connection dialog appears.
Set the server name to the server you are using, .\SQLEXPRESS in this case. Set the database to Northwind.
Click Ok. You are returned to the Configure Connection screen.
Click Next.
Select Specify Columns from a Table or View and do the following:
Choose the Customers table from the drop-down list.
In the Columns section, select CustomerID, CompanyName, ContactName, and ContactTitle to display those columns.
At this point you have the option to click the Advanced button to specify that the SqlDataSource component should generate Insert, Update, and Delete statements for the data retrieved.
Click Next.
Test your query to make sure SqlDataSource retrieves your data.
Click Finish to close the configuration wizard. SqlDataSource is set up to retrieve the Customers data from the Northwind database.
In the properties window for WebDataGrid, set DataSourceID to be the id of the SqlDataSource component.
Set the DataKeyFields property to CustomerID.
Run the application. WebDataGrid binds to the customers table and displays its data.