DetailsViewCommandEventArgs クラス
アセンブリ: System.Web (system.web.dll 内)
構文
解説ButtonField、CommandField、または TemplateField 行フィールド内のボタンがクリックされると、DetailsView コントロールが ItemCommand イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチンを実行するイベント ハンドラを提供できます。
メモ |
|---|
| また、DetailsView コントロールは、特定のボタン (CommandName プロパティが "Delete"、"Insert"、"Page"、または "Update" に設定されているボタン) がクリックされた場合、その他の特別なイベントを発生させます。これらのボタンを使用する場合は、コントロールから提供される特別なイベントのいずれか (ItemDeleted や ItemDeleting など) の使用を考慮する必要があります。 |
DetailsViewCommandEventArgs オブジェクトはイベント ハンドラに渡されます。イベントを発生させたボタンにコマンド名またはコマンド引数が指定されている場合は、DetailsViewCommandEventArgs オブジェクトを使用して、それらの値を確認できます。クリックされたボタンのコマンド名を確認するには CommandName プロパティを、コマンド引数を確認するには CommandArgument プロパティを使用します。また、CommandSource プロパティを使用して、イベントを発生させた DetailsView コントロールにアクセスすることもできます。
DetailsViewCommandEventArgs クラスのインスタンスの初期プロパティ値の一覧については、DetailsViewCommandEventArgs コンストラクタのトピックを参照してください。
使用例ItemCommand イベントのイベント ハンドラに渡される DetailsViewCommandEventArgs オブジェクトを使用して、ユーザーがクリックしたボタンのコマンド名を確認する方法のコード例を次に示します。この例ではシングル ファイルのコーディング モデルを使用します。
<%@ page language="VB" autoeventwireup="false" %> <script runat="server"> Sub ItemDetailsView_ItemCommand(ByVal sender As Object, _ ByVal e As DetailsViewCommandEventArgs) _ Handles ItemDetailsView.ItemCommand ' Use the CommandName property to determine which button ' was clicked. If e.CommandName = "Add" Then ' Add the customer to the customer list. ' Get the row that contains the company name. In this ' example, the company name is in the second row (index 1) ' of the DetailsView control. Dim row As DetailsViewRow = ItemDetailsView.Rows(1) ' Get the company's name from the appropriate cell. ' In this example, the company name is in the second cell ' (index 1) of the row. Dim name As String = row.Cells(1).Text ' Create a ListItem object with the company name. Dim item As New ListItem(name) ' Add the ListItem object to the ListBox control, if the ' item does not already exist. If Not CustomerListBox.Items.Contains(item) Then CustomerListBox.Items.Add(item) End If End If End Sub </script> <html> <body> <form runat="server"> <h3>DetailsViewCommandEventArgs Example</h3> <asp:detailsview id="ItemDetailsView" datasourceid="DetailsViewSource" allowpaging="true" autogeneraterows="false" runat="server"> <fields> <asp:boundfield datafield="CustomerID" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="Address" headertext="Address"/> <asp:boundfield datafield="City" headertext="City"/> <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/> <asp:boundfield datafield="Country" headertext="Country"/> <asp:buttonfield buttontype="Link" causesvalidation="false" text="Add to List" commandname="Add"/> </fields> </asp:detailsview> <br/><br/> Selected Customers:<br/> <asp:listbox id="CustomerListBox" runat="server"/> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="DetailsViewSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ page language="C#" %> <script runat="server"> void ItemDetailsView_ItemCommand(Object sender, DetailsViewCommandEventArgs e) { // Use the CommandName property to determine which button // was clicked. if (e.CommandName == "Add") { // Add the customer to the customer list. // Get the row that contains the company name. In this // example, the company name is in the second row (index 1) // of the DetailsView control. DetailsViewRow row = ItemDetailsView.Rows[1]; // Get the company's name from the appropriate cell. // In this example, the company name is in the second cell // (index 1) of the row. String name = row.Cells[1].Text; // Create a ListItem object with the company name. ListItem item = new ListItem(name); // Add the ListItem object to the ListBox control, if the // item does not already exist. if (!CustomerListBox.Items.Contains(item)) { CustomerListBox.Items.Add(item); } } } </script> <html> <body> <form runat="server"> <h3>DetailsViewCommandEventArgs Example</h3> <asp:detailsview id="ItemDetailsView" datasourceid="DetailsViewSource" allowpaging="true" autogeneraterows="false" onitemcommand="ItemDetailsView_ItemCommand" runat="server"> <fields> <asp:boundfield datafield="CustomerID" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="Address" headertext="Address"/> <asp:boundfield datafield="City" headertext="City"/> <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/> <asp:boundfield datafield="Country" headertext="Country"/> <asp:buttonfield buttontype="Link" causesvalidation="false" text="Add to List" commandname="Add"/> </fields> </asp:detailsview> <br/><br/> Selected Customers:<br/> <asp:listbox id="CustomerListBox" runat="server"/> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="DetailsViewSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
前の例の分離コード コーディング モデルを次のコード例に示します。この例を正常に動作させるには、以下のコードを関連付けられた分離コード ファイルにコピーする必要があります。
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DefaultVB.aspx.vb" Inherits="DefaultVB" %> <html> <body> <form id="Form1" runat="server"> <h3>DetailsViewCommandEventArgs Example</h3> <asp:detailsview id="ItemDetailsView" datasourceid="DetailsViewSource" allowpaging="true" autogeneraterows="false" onitemcommand="ItemDetailsView_ItemCommand" runat="server"> <fields> <asp:boundfield datafield="CustomerID" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="Address" headertext="Address"/> <asp:boundfield datafield="City" headertext="City"/> <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/> <asp:boundfield datafield="Country" headertext="Country"/> <asp:buttonfield buttontype="Link" causesvalidation="false" text="Add to List" commandname="Add"/> </fields> </asp:detailsview> <br/><br/> Selected Customers:<br/> <asp:listbox id="CustomerListBox" runat="server"/> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="DetailsViewSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <html> <body> <form id="Form1" runat="server"> <h3>DetailsViewCommandEventArgs Example</h3> <asp:detailsview id="ItemDetailsView" datasourceid="DetailsViewSource" allowpaging="true" autogeneraterows="false" onitemcommand="ItemDetailsView_ItemCommand" runat="server"> <fields> <asp:boundfield datafield="CustomerID" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="Address" headertext="Address"/> <asp:boundfield datafield="City" headertext="City"/> <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/> <asp:boundfield datafield="Country" headertext="Country"/> <asp:buttonfield buttontype="Link" causesvalidation="false" text="Add to List" commandname="Add"/> </fields> </asp:detailsview> <br/><br/> Selected Customers:<br/> <asp:listbox id="CustomerListBox" runat="server"/> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="DetailsViewSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { public void ItemDetailsView_ItemCommand(Object sender, DetailsViewCommandEventArgs e) { // Use the CommandName property to determine which button // was clicked. if (e.CommandName == "Add") { // Add the customer to the customer list. // Get the row that contains the company name. In this // example, the company name is in the second row (index 1) // of the DetailsView control. DetailsViewRow row = ItemDetailsView.Rows[1]; // Get the company's name from the appropriate cell. // In this example, the company name is in the second cell // (index 1) of the row. String name = row.Cells[1].Text; // Create a ListItem object with the company name. ListItem item = new ListItem(name); // Add the ListItem object to the ListBox control, if the // item does not already exist. if (!CustomerListBox.Items.Contains(item)) { CustomerListBox.Items.Add(item); } } } }
.NET Framework のセキュリティ
継承階層System.EventArgs
System.Web.UI.WebControls.CommandEventArgs
System.Web.UI.WebControls.DetailsViewCommandEventArgs
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照DetailsViewCommandEventArgs コンストラクタ
アセンブリ: System.Web (system.web.dll 内)
構文Dim commandSource As Object Dim originalArgs As CommandEventArgs Dim instance As New DetailsViewCommandEventArgs(commandSource, originalArgs)
public function DetailsViewCommandEventArgs ( commandSource : Object, originalArgs : CommandEventArgs )
解説このコンストラクタを使用して、DetailsViewCommandEventArgs クラスの新しいインスタンスを初期化します。
DetailsViewCommandEventArgs のインスタンスの初期プロパティ値を次の表に示します。
| CommandArgument | originalArgs パラメータに格納された CommandEventArgs の CommandArgument プロパティ値。 |
| CommandName | originalArgs パラメータに格納された CommandEventArgs オブジェクトの CommandName プロパティ値。 |
| CommandSource |
メモ |
|---|
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照DetailsViewCommandEventArgs プロパティ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| CommandArgument | コマンドの引数を取得します。 ( CommandEventArgs から継承されます。) |
| CommandName | コマンド名を取得します。 ( CommandEventArgs から継承されます。) |
| CommandSource | コマンドのソースを取得します。 |
参照DetailsViewCommandEventArgs メソッド
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
| GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
| GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
| ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
参照DetailsViewCommandEventArgs メンバ
DetailsViewCommandEventArgs データ型で公開されるメンバを以下の表に示します。
パブリック コンストラクタ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| CommandArgument | コマンドの引数を取得します。(CommandEventArgs から継承されます。) |
| CommandName | コマンド名を取得します。(CommandEventArgs から継承されます。) |
| CommandSource | コマンドのソースを取得します。 |
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
| GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
| GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
| ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照- DetailsViewCommandEventArgsのページへのリンク
.gif)