Control.OnDataBinding(EventArgs) Método
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Aciona o evento DataBinding.
protected:
virtual void OnDataBinding(EventArgs ^ e);
protected virtual void OnDataBinding(EventArgs e);
abstract member OnDataBinding : EventArgs -> unit
override this.OnDataBinding : EventArgs -> unit
Protected Overridable Sub OnDataBinding (e As EventArgs)
O exemplo a seguir demonstra como substituir o OnDataBinding método para adicionar controles filho ao controle pai de uma fonte de dados.
// Override to create the repeated items from the DataSource.
protected override void OnDataBinding(EventArgs e) {
base.OnDataBinding(e);
if (DataSource != null) {
// Clear any existing child controls.
Controls.Clear();
// Clear any previous view state for the existing child controls.
ClearChildViewState();
// Iterate over the DataSource, creating a new item for each data item.
IEnumerator dataEnum = DataSource.GetEnumerator();
int i = 0;
while(dataEnum.MoveNext()) {
// Create an item.
RepeaterItem item = new RepeaterItem(i, dataEnum.Current);
// Initialize the item from the template.
ItemTemplate.InstantiateIn(item);
// Add the item to the ControlCollection.
Controls.Add(item);
i++;
}
// Prevent child controls from being created again.
ChildControlsCreated = true;
// Store the number of items created in view state for postback scenarios.
ViewState["NumItems"] = i;
}
}
' Override to create the repeated items from the DataSource.
Protected Overrides Sub OnDataBinding(E As EventArgs)
MyBase.OnDataBinding(e)
If Not DataSource Is Nothing
' Clear any existing child controls.
Controls.Clear()
' Clear any previous view state for the existing child controls.
ClearChildViewState()
' Iterate over the DataSource, creating a new item for each data item.
Dim DataEnum As IEnumerator = DataSource.GetEnumerator()
Dim I As Integer = 0
Do While (DataEnum.MoveNext())
' Create an item.
Dim Item As RepeaterItemVB = New RepeaterItemVB(I, DataEnum.Current)
' Initialize the item from the template.
ItemTemplate.InstantiateIn(Item)
' Add the item to the ControlCollection.
Controls.Add(Item)
I = I + 1
Loop
' Prevent child controls from being created again.
ChildControlsCreated = true
' Store the number of items created in view state for postback scenarios.
ViewState("NumItems") = I
End If
End Sub
Esse método notifica um controle de servidor para executar qualquer lógica para associar dados associados a ele.
Se quiser manipular o DataBinding evento, substitua esse método de manipulação de eventos. Isso garante que todos os delegados anexados ao DataBinding evento sejam invocados.
Produto | Versões |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: