How to Bind an Object to a GridView in Code

Binding objects in a GridView displays record sets from the object. Data objects such as DataSets, DataTables and Collections provide binding capabilities with GridView controls. The .NET GridView automatically parses the information and displays the results to your Web page or desktop application. Use the "DataSource" and "Bind" functions for the GridView to accomplish the link between the two objects.

Instructions

    • 1

      Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET Framework," then click "Visual Studio." Open your ASP.NET project in VS.

    • 2

      Double-click the ASP form that contains the GridView and data object. After the designer loads the form, right-click on the form and select "View Code."

    • 3

      Set the data object as the GridView "DataSource" property. For instance, the following code assigns a dataset object to the "DataSource" property for a GridView named "grid1":

      grid1.DataSource = dataset;

    • 4

      Bind the object to the GridView. After you assign a data source, you must call the "DataBind" function. The following code shows how to bind the data:

      grid1.DataBind();

Related Searches:

References

Comments

Related Ads

Featured