GridView::DataBind Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Binds the data source to the GridView control. This method cannot be inherited.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

virtual void DataBind() override sealed

Use the DataBind() method to bind data from a data source to the GridView control. This method resolves all data-binding expressions in the active template of the control.

The DataBind method is called automatically if the DataSourceID property of the GridView control refers to a valid data source control.

Instead of manually calling the DataBind method, you can use model binding with your DataBind control by setting the SelectMethod property to the name of a method that returns data for the GridView. The GridView is then automatically populated with the data that is returned from the select method. Model binding can simplify your code for working with data. For more information, see Model Binding and Web Forms.

The following example demonstrates how to use the DataBind() method to bind a data source to a GridView control.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top