Bewerken

Delen via


BaseDataBoundControl.DataSourceID Property

Definition

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

public:
 virtual property System::String ^ DataSourceID { System::String ^ get(); void set(System::String ^ value); };
[System.Web.UI.Themeable(false)]
public virtual string DataSourceID { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.DataSourceID : string with get, set
Public Overridable Property DataSourceID As String

Property Value

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

Attributes

Examples

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>
<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>

Remarks

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.

Applies to

See also