Condividi tramite


BaseDataBoundControl.RequiresDataBinding Proprietà

Definizione

Ottiene o imposta un valore che indica se il DataBind() metodo deve essere chiamato.

protected:
 property bool RequiresDataBinding { bool get(); void set(bool value); };
protected bool RequiresDataBinding { get; set; }
member this.RequiresDataBinding : bool with get, set
Protected Property RequiresDataBinding As Boolean

Valore della proprietà

Il valore restituito è true se il metodo del controllo associato a dati deve essere chiamato prima del DataBind() rendering del controllo; in caso contrario, il valore è false.

Esempio

Nell'esempio di codice seguente viene illustrato come la RequiresDataBinding proprietà viene utilizzata da una classe di controllo associata a dati derivata. Dopo che i GetData dati vengono recuperati dal metodo e associati al controllo con il PerformDataBinding metodo , la RequiresDataBinding proprietà viene impostata su false e il MarkAsDataBound metodo viene chiamato per segnalare che il controllo ha completato l'associazione e non richiede più questa proprietà durante il ciclo di vita della pagina corrente. Questo esempio di codice fa parte di un esempio più ampio fornito per la DataBoundControl classe .

protected override void PerformSelect() {            

   // Call OnDataBinding here if bound to a data source using the
   // DataSource property (instead of a DataSourceID), because the
   // databinding statement is evaluated before the call to GetData.       
    if (!IsBoundUsingDataSourceID) {
        OnDataBinding(EventArgs.Empty);
    }            
    
    // The GetData method retrieves the DataSourceView object from  
    // the IDataSource associated with the data-bound control.            
    GetData().Select(CreateDataSourceSelectArguments(), 
        OnDataSourceViewSelectCallback);
    
    // The PerformDataBinding method has completed.
    RequiresDataBinding = false;
    MarkAsDataBound();
    
    // Raise the DataBound event.
    OnDataBound(EventArgs.Empty);
}
Protected Overrides Sub PerformSelect()

    ' Call OnDataBinding here if bound to a data source using the 
    ' DataSource property (instead of a DataSourceID) because the 
    ' data-binding statement is evaluated before the call to GetData.
    If Not IsBoundUsingDataSourceID Then
        OnDataBinding(EventArgs.Empty)
    End If

    ' The GetData method retrieves the DataSourceView object from the 
    ' IDataSource associated with the data-bound control.            
    GetData().Select(CreateDataSourceSelectArguments(), _
        AddressOf OnDataSourceViewSelectCallback)

    ' The PerformDataBinding method has completed.
    RequiresDataBinding = False
    MarkAsDataBound()

    ' Raise the DataBound event.
        OnDataBound(EventArgs.Empty)

End Sub

Commenti

Se si imposta la RequiresDataBinding proprietà su true quando il controllo associato a dati ha già iniziato a eseguire il rendering dell'output nella pagina, la richiesta HTTP corrente non è un callback e si usa la DataSourceID proprietà per identificare il controllo origine dati a cui eseguire l'associazione, il DataBind metodo viene chiamato immediatamente. In questo caso, la RequiresDataBinding proprietà non è effettivamente impostata su true.

Si applica a

Vedi anche