Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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)
[ThemeableAttribute(false)]
public virtual string DataSourceID { get; set; }
<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.

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>

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.