BaseDataBoundControl.DataSourceID Proprietà

Definizione

Ottiene o imposta l'ID del controllo da cui il controllo associato a dati recupera l'elenco di elementi di dati.

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

Valore della proprietà

ID di un controllo che rappresenta l'origine dati da cui il controllo associato a dati recupera i dati. Il valore predefinito è Empty.

Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come viene utilizzata la DataSourceID proprietà di un controllo associato a dati. Il GridView controllo è associato al controllo impostandone la DataSourceIDSqlDataSource proprietà su "AuthorsSqlDataSource", l'ID del SqlDataSource controllo. Quando la DataSourceID proprietà viene impostata (anziché la DataSource proprietà ), il controllo associato a dati viene associato automaticamente al controllo origine dati in fase di esecuzione.

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

Commenti

Se il controllo associato a dati è già stato inizializzato (il ConfirmInitState metodo viene chiamato o OnPagePreLoad l'evento viene gestito) quando si imposta la DataSourceID proprietà , viene chiamato il OnDataPropertyChanged metodo , che imposta la RequiresDataBinding proprietà su true.

Questa proprietà non può essere impostata da temi oppure temi di fogli di stile. Per altre informazioni, vedere ThemeableAttribute e ASP.NET Temi e interfacce.

Si applica a

Vedi anche