Control.OnDataBinding(EventArgs) Metoda

Definicja

DataBinding Zgłasza zdarzenie.

C#
protected virtual void OnDataBinding(EventArgs e);

Parametry

e
EventArgs

EventArgs Obiekt, który zawiera dane zdarzenia.

Przykłady

W poniższym przykładzie pokazano, jak zastąpić metodę OnDataBinding dodawania kontrolek podrzędnych do kontrolki nadrzędnej ze źródła danych.

C#
// 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;
    }
}

Uwagi

Ta metoda powiadamia kontrolkę serwera o wykonaniu dowolnej logiki dla skojarzonych z nią danych powiązania.

Jeśli chcesz obsłużyć DataBinding zdarzenie, należy zastąpić tę metodę obsługi zdarzeń. Dzięki temu wszystkie delegaty dołączone do DataBinding zdarzenia są wywoływane.

Dotyczy

Produkt Wersje
.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

Zobacz też