Export (0) Print
Expand All

BaseDataBoundControl.DataSourceID Property

Gets or sets the ID of the control from which the data-bound control retrieves its list of data items.

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

'Declaration
<ThemeableAttribute(False)> _
Public Overridable Property DataSourceID As String
'Usage
Dim instance As BaseDataBoundControl 
Dim value As String 

value = instance.DataSourceID

instance.DataSourceID = value
<asp:BaseDataBoundControl DataSourceID="String" />

Property Value

Type: System.String
The ID of a control that represents the data source from which the data-bound control retrieves its data. The default is String.Empty.

If the data-bound control has already been initialized (the ConfirmInitState method is called or OnPagePreLoad event is handled) when you set the DataSourceID property, the OnDataPropertyChanged method is called, which sets the RequiresDataBinding property to true.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.

The following code example demonstrates how the DataSourceID property of a data-bound control is used. The GridView control is associated to the SqlDataSource control by setting its DataSourceID property to "AuthorsSqlDataSource", the ID of the SqlDataSource control. When the DataSourceID property is set (instead of the DataSource property), the data-bound control automatically binds to the data source control at run time.

<asp:sqldatasource id="CustomersSource"
  selectcommand="SELECT CustomerID, CompanyName, FirstName, LastName FROM SalesLT.Customer"
  connectionstring="<%$ ConnectionStrings:AWLTConnectionString %>" 
  runat="server"/>

<asp:gridview id="CustomersGridView" 
  datasourceid="CustomersSource" 
  autogeneratecolumns="False"
  emptydatatext="No data available." 
  allowpaging="True" 
  runat="server" DataKeyNames="CustomerID">
    <Columns>
        <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
            InsertVisible="False" ReadOnly="True" SortExpression="CustomerID" />
        <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" 
            SortExpression="CompanyName" />
        <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
            SortExpression="FirstName" />
        <asp:BoundField DataField="LastName" HeaderText="LastName" 
            SortExpression="LastName" />
    </Columns>
</asp:gridview>

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft