System.Web.UI.WebControls Namespace BaseDataList Class
Binds a data source to the control.
[ VB ]
Overrides Public Sub DataBind ( )
[ C# ]
public override void DataBind ( );
[ C++ ]
public: void DataBind ( );
[ JScript ]
public override function DataBind ( );
Use the DataBind method to bind the data source specified by the DataSource property with the data list control. By binding the data source with a data listing control, the information in the data source is displayed in a data listing control.
The DataBind method is also commonly used to synchronize the data source and a data listing control after information in the data source is updated. This allows any changes in the data source to also be updated in a data listing control.
The below snippet demonstrates how to dynamically bind a data source to a DataList control when the page loads at run time. The data source in this case is an SqlDataReader.
<script language = "C#" runat = "server">
void Page_Load ( Object src, EventArgs e ) {
// ... code to fetch data into a datareader here ...
// bind the datalist to the datareader
myList.DataSource = myReader;
myList.DataBind ( );
// close the connection
myConn.Close ( );
}
</script>
<asp:datalist id = "myList" repeatcolumns=2 runat = "server">
...
</asp:datalist>
<script language = "VB" runat = "server">
sub Page_Load ( ByVal src as Object, ByVal e as EventArgs )
' ... code to fetch data into a datareader here ...
' bind the datalist to the datareader
myList.DataSource = myReader
myList.DataBind ( )
' close the connection
myConn.Close ( )
end sub
</script>
<asp:datalist id = "myList" repeatcolumns=2 runat = "server">
...
</asp:datalist> |
|
C# |
VB |
Show me
BaseDataList Members