List.ItemCommand イベント

定義

List コントロールに関連付けられているコマンドをユーザーが選択すると発生します。 この API は、互換性のために残されています。 ASP.NET モバイル アプリケーションを開発する方法については、「ASP.NET を使用した Mobile Apps & サイト」を参照してください。

public:
 event System::Web::UI::MobileControls::ListCommandEventHandler ^ ItemCommand;
public event System.Web.UI.MobileControls.ListCommandEventHandler ItemCommand;
member this.ItemCommand : System.Web.UI.MobileControls.ListCommandEventHandler 
Public Custom Event ItemCommand As ListCommandEventHandler 

イベントの種類

次のコード例は、 イベントを ItemCommand 使用して、リスト内の項目の状態を変更し、状態の合計を再計算するメソッドを呼び出す方法を示しています。 この例は、概要の大きな例の List 一部です。

private void Status_ItemCommand(object sender, 
    ListCommandEventArgs e)
{
    const string spec = "You now have {0} " + 
        "tasks done, {1} tasks scheduled, and " +
        "{2} tasks pending.";

    // Move selection to next status toward 'done'
    switch (e.ListItem.Value)
    {
        case "scheduled":
            schedCount -= 1;
            pendCount += 1;
            e.ListItem.Value = "pending";
            break;
        case "pending":
            pendCount -= 1;
            doneCount += 1;
            e.ListItem.Value = "done";
            break;
    }

    // Show the status of the current task
    Label1.Text = e.ListItem.Text + " is " +
        e.ListItem.Value;

    // Show current selection counts
    Label2.Text = String.Format(spec, doneCount, 
        schedCount, pendCount);
}
Private Sub Status_ItemCommand(ByVal sender As Object, _
    ByVal e As ListCommandEventArgs)

    Const spec As String = "You now have {0} tasks done, {1} " & _
        "tasks scheduled, and {2} tasks pending."

    ' Move selection to next status toward 'done'
    Select Case e.ListItem.Value
        Case "scheduled"
            schedCount -= 1
            pendCount += 1
            e.ListItem.Value = "pending"
        Case "pending"
            pendCount -= 1
            doneCount += 1
            e.ListItem.Value = "done"
            
    End Select

    ' Show the status of the current task
    Label1.Text = e.ListItem.Text & " is " & _
        e.ListItem.Value

    ' Show current selection counts
    Label2.Text = String.Format(spec, doneCount, _
        schedCount, pendCount)
End Sub

注釈

テンプレートを使用してリストをレンダリングすると、 ItemCommand イベント ハンドラーは、ASP.NET のイベント バブル メカニズムを介して呼び出されます。 イベント ハンドラーには、 型 ListCommandEventArgsの引数が渡されます。この引数には、イベントを生成したコントロールのソース項目と CommandName プロパティに関する情報が含まれます。 これにより、複数の関連する相互作用を持つ 1 つのリスト アイテムをレンダリングできます。

既定のレンダリングでは、コントロールには、ユーザーがリスト アイテムをクリックできるようにする基本的なユーザー インターフェイス (UI) が用意されています。 ポストバックでは、 ItemCommand イベント ハンドラーが 型 ListCommandEventArgsの引数を使用して呼び出されます。この引数には、ソース項目に関する情報が含まれます。 CommandNameこのオブジェクトの プロパティは ですnull

適用対象

こちらもご覧ください