次の方法で共有


Control.OnDataBinding メソッド

DataBinding イベントを発生させます。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Protected Overridable Sub OnDataBinding ( _
    e As EventArgs _
)
'使用
Dim e As EventArgs

Me.OnDataBinding(e)
protected virtual void OnDataBinding (
    EventArgs e
)
protected:
virtual void OnDataBinding (
    EventArgs^ e
)
protected void OnDataBinding (
    EventArgs e
)
protected function OnDataBinding (
    e : EventArgs
)
適用できません。

パラメータ

  • e
    イベント データを格納している EventArgs オブジェクト。

解説

このメソッドは、サーバー コントロールに関連付けられているデータ バインド ロジックを実行するように、サーバー コントロールに通知します。

DataBinding イベントを処理する場合は、このイベント処理メソッドをオーバーライドする必要があります。これにより、DataBinding イベントに結びつけられているすべてのデリゲートが起動します。

使用例

OnDataBinding メソッドをオーバーライドして、データ ソースから親コントロールに子コントロールを追加する方法の例を次に示します。

' 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
// 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 void OnDataBinding(EventArgs e)
{
    super.OnDataBinding(e);

    if (get_DataSource() != null) {
        // Clear any existing child controls.
        get_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 = get_DataSource().GetEnumerator();
        int i = 0;
        while (dataEnum.MoveNext()) {
            // Create an item.
            RepeaterItem item = new RepeaterItem(i, dataEnum.get_Current());
            // Initialize the item from the template.
            get_ItemTemplate().InstantiateIn(item);
            // Add the item to the ControlCollection.
            get_Controls().Add(item);
            i++;
        }
        // Prevent child controls from being created again.
        set_ChildControlsCreated(true);
        // Store the number of items created in view state for postback
        // scenarios.
        get_ViewState().set_Item("NumItems", (Int32)i);
    }
} //OnDataBinding

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

Control クラス
Control メンバ
System.Web.UI 名前空間
DataBinding
DataBind