DetailsViewInsertEventArgs クラス
アセンブリ: System.Web (system.web.dll 内)


DetailsView コントロールは、コントロール内の Insert ボタン (CommandName プロパティが "Insert" に設定されたボタン) がクリックされ、DetailsView コントロールが実際にレコードを挿入する前に ItemInserting イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチン (データ ソースにレコードを挿入する前にレコードの値を HTML エンコーディングするなど) を実行するイベント ハンドラを提供できます。
DetailsViewInsertEventArgs オブジェクトがイベント ハンドラに渡されることにより、DetailsView コントロールに送信される省略可能なコマンド引数の値を確認したり、挿入操作をキャンセルする必要があることを示したりできます。コマンド引数の値を確認するには、CommandArgument プロパティを使用します。挿入操作をキャンセルするには、Cancel プロパティを true に設定します。また、Values プロパティを使用して、新規レコードのフィールド値を読み込んだり、変更したりすることもできます。
イベント処理の詳細については、「イベントの利用」を参照してください。
DetailsViewInsertEventArgs クラスのインスタンスの初期プロパティ値の一覧については、DetailsViewInsertEventArgs コンストラクタのトピックを参照してください。

ItemInserting イベントのイベント ハンドラに渡される DetailsViewInsertEventArgs オブジェクトを使用して、挿入操作をキャンセルする方法のコード例を次に示します。
<%@ Page language="VB" autoeventwireup="false" %> <script runat="server"> Sub CustomerDetailsView_ItemInserting(ByVal sender As Object, _ ByVal e As DetailsViewInsertEventArgs) _ Handles CustomerDetailsView.ItemInserting ' Use the Values property to retrieve the key field value. Dim keyValue As String = e.Values("CustomerID").ToString() ' Insert the record only if the key field is four characters ' long; otherwise, cancel the insert operation. If keyValue.Length = 4 Then ' Change the key field value to upper case before inserting ' the record in the data source. e.Values("CustomerID") = keyValue.ToUpper() MessageLabel.Text = "" Else MessageLabel.Text = "The key field must have four digits." e.Cancel = True End If End Sub </script> <html> <body> <form runat="server"> <h3>DetailsViewInsertEventArgs Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogenerateinsertbutton="true" autogeneraterows="true" allowpaging="true" oniteminserting="CustomerDetailsView_ItemInserting" runat="server"> <fieldheaderstyle backcolor="Navy" forecolor="White"/> </asp:detailsview> <asp:label id="MessageLabel" forecolor="Red" 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]" insertcommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomerDetailsView_ItemInserting(Object sender, DetailsViewInsertEventArgs e) { // Use the Values property to retrieve the key field value. String keyValue = e.Values["CustomerID"].ToString(); // Insert the record only if the key field is four characters // long; otherwise, cancel the insert operation. if (keyValue.Length == 4) { // Change the key field value to upper case before inserting // the record in the data source. e.Values["CustomerID"] = keyValue.ToUpper(); MessageLabel.Text = ""; } else { MessageLabel.Text = "The key field must have four digits."; e.Cancel = true; } } </script> <html> <body> <form runat="server"> <h3>DetailsViewInsertEventArgs Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogenerateinsertbutton="true" autogeneraterows="true" allowpaging="true" oniteminserting="CustomerDetailsView_ItemInserting" runat="server"> <fieldheaderstyle backcolor="Navy" forecolor="White"/> </asp:detailsview> <asp:label id="MessageLabel" forecolor="Red" 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]" insertcommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>


System.EventArgs
System.ComponentModel.CancelEventArgs
System.Web.UI.WebControls.DetailsViewInsertEventArgs


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DetailsViewInsertEventArgs コンストラクタ
アセンブリ: System.Web (system.web.dll 内)


このコンストラクタを使用して、DetailsViewInsertEventArgs クラスの新しいインスタンスを初期化します。
DetailsViewInsertEventArgs クラスのインスタンスの初期プロパティ値を次の表に示します。
![]() |
---|

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DetailsViewInsertEventArgs プロパティ

名前 | 説明 | |
---|---|---|
![]() | Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。) |
![]() | CommandArgument | DetailsView コントロールに渡される、挿入処理のコマンド引数を取得します。 |
![]() | Values | 挿入するレコードのフィールドの名前/値ペアを格納しているディクショナリを取得します。 |

DetailsViewInsertEventArgs メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

DetailsViewInsertEventArgs メンバ
DetailsViewInsertEventArgs データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。) |
![]() | CommandArgument | DetailsView コントロールに渡される、挿入処理のコマンド引数を取得します。 |
![]() | Values | 挿入するレコードのフィールドの名前/値ペアを格納しているディクショナリを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- DetailsViewInsertEventArgsのページへのリンク