BaseDataBoundControl.DataSourceID BaseDataBoundControl.DataSourceID BaseDataBoundControl.DataSourceID BaseDataBoundControl.DataSourceID Property

定义

获取或设置控件的 ID,数据绑定控件从该控件中检索其数据项列表。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; }
member this.DataSourceID : string with get, set
Public Overridable Property DataSourceID As String

属性值

表示数据源的控件的 ID,数据绑定控件从该控件中检索其数据。The ID of a control that represents the data source from which the data-bound control retrieves its data. 默认值为 EmptyThe default is Empty.

示例

下面的代码示例演示如何使用DataSourceID数据绑定控件的属性。The following code example demonstrates how the DataSourceID property of a data-bound control is used. 通过将控件的DataSourceID属性设置SqlDataSourceSqlDataSource "AuthorsSqlDataSource", 控件的 ID 将控件关联到控件。GridViewThe GridView control is associated to the SqlDataSource control by setting its DataSourceID property to "AuthorsSqlDataSource", the ID of the SqlDataSource control. 如果设置DataSourceID了属性 (而不是DataSource属性), 数据绑定控件将在运行时自动绑定到数据源控件。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>

注解

如果ConfirmInitState OnPagePreLoad DataSourceID 设置了RequiresDataBinding属性, 则在设置该属性时, 如果数据绑定控件已经初始化 (方法被调用或事件), 则调用方法,该方法将属性设置为OnDataPropertyChanged true.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. 有关详细信息, 请ThemeableAttribute参阅和ASP.NET 主题和外观For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

适用于

另请参阅