DetailsViewInsertedEventHandler デリゲート
アセンブリ: System.Web (system.web.dll 内)

Public Delegate Sub DetailsViewInsertedEventHandler ( _ sender As Object, _ e As DetailsViewInsertedEventArgs _ )
public delegate void DetailsViewInsertedEventHandler ( Object sender, DetailsViewInsertedEventArgs e )
public delegate void DetailsViewInsertedEventHandler ( Object^ sender, DetailsViewInsertedEventArgs^ e )
/** @delegate */ public delegate void DetailsViewInsertedEventHandler ( Object sender, DetailsViewInsertedEventArgs e )

DetailsView コントロールは、コントロール内の Insert ボタン (CommandName プロパティが "Insert" に設定されたボタン) がクリックされた場合に、DetailsView コントロールが実際にレコードを挿入した後に ItemInserted イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチン (挿入操作の結果を確認するなど) を実行するイベント ハンドラを提供できます。
DetailsViewInsertedEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを識別してください。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「イベントとデリゲート」を参照してください。

DetailsViewInsertedEventHandler デリゲートを、プログラムによって DetailsView コントロールの ItemInserted イベントに追加する方法のコード例を次に示します。
<%@ page language="VB"%> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Create a new DetailsView object. Dim customerDetailsView As New DetailsView() ' Set the DetailsView object's properties. customerDetailsView.ID = "CustomerDetailsView" customerDetailsView.DataSourceID = "DetailsViewSource" customerDetailsView.AutoGenerateRows = True customerDetailsView.AutoGenerateInsertButton = True customerDetailsView.AllowPaging = true Dim keyArray() As String = {"CustomerID"} customerDetailsView.DataKeyNames = keyArray ' Programmatically register the event-handling method ' for the ItemInserted event of a DetailsView control. AddHandler customerDetailsView.ItemInserted, _ AddressOf CustomerDetailsView_ItemInserted ' Add the DetailsView object to the Controls collection ' of the PlaceHolder control. DetailsViewPlaceHolder.Controls.Add(customerDetailsView) End Sub Sub CustomerDetailsView_ItemInserted(ByVal sender As Object, _ ByVal e As DetailsViewInsertedEventArgs) ' Use the Exception property to determine whether an exception ' occurred during the insert operation. If e.Exception Is Nothing Then ' Use the Values property to get the value entered by ' the user for the CompanyName field. Dim name As String = e.Values("CompanyName").ToString() ' Display a confirmation message. MessageLabel.Text = name & " added successfully. " Else ' Insert the code to handle the exception. MessageLabel.Text = e.Exception.Message ' Use the ExceptionHandled property to indicate that the ' exception is already handled. e.ExceptionHandled = True ' When an exception occurs, keep the DetailsView ' control in insert mode. e.KeepInInsertMode = True End If End Sub </script> <html> <body> <form runat="server"> <h3>DetailsViewInsertedEventHandler Example</h3> <!-- Use a PlaceHolder control as the container for the --> <!-- dynamically generated DetailsView control. --> <asp:PlaceHolder id="DetailsViewPlaceHolder" runat="server"/> <br/><br/> <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 Page_Load(Object sender, EventArgs e) { // Create a new DetailsView object. DetailsView customerDetailsView = new DetailsView(); // Set the DetailsView object's properties. customerDetailsView.ID = "CustomerDetailsView"; customerDetailsView.DataSourceID = "DetailsViewSource"; customerDetailsView.AutoGenerateRows = true; customerDetailsView.AutoGenerateInsertButton = true; customerDetailsView.AllowPaging = true; customerDetailsView.DataKeyNames = new String[1] { "CustomerID" }; // Programmatically register the event-handling method // for the ItemInserted event of a DetailsView control. customerDetailsView.ItemInserted += new DetailsViewInsertedEventHandler( this.CustomerDetailsView_ItemInserted); // Add the DetailsView object to the Controls collection // of the PlaceHolder control. DetailsViewPlaceHolder.Controls.Add(customerDetailsView); } void CustomerDetailsView_ItemInserted(Object sender, DetailsViewInsertedEventArgs e) { // Use the Exception property to determine whether an exception // occurred during the insert operation. if (e.Exception == null) { // Use the Values property to get the value entered by // the user for the CompanyName field. String name = e.Values["CompanyName"].ToString(); // Display a confirmation message. MessageLabel.Text = name + " added successfully. "; } else { // Insert the code to handle the exception. MessageLabel.Text = e.Exception.Message; // Use the ExceptionHandled property to indicate that the // exception is already handled. e.ExceptionHandled = true; // When an exception occurs, keep the DetailsView // control in insert mode. e.KeepInInsertMode = true; } } </script> <html> <body> <form runat="server"> <h3>DetailsViewInsertedEventHandler Example</h3> <!-- Use a PlaceHolder control as the container for the --> <!-- dynamically generated DetailsView control. --> <asp:PlaceHolder id="DetailsViewPlaceHolder" runat="server"/> <br/><br/> <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>
DetailsViewInsertedEventHandler デリゲートを、宣言によって DetailsView コントロールの ItemInserted イベントに追加する方法のコード例を次に示します。
<%@ Page language="VB" autoeventwireup="false" %> <script runat="server"> Sub CustomerDetailsView_ItemInserted(ByVal sender As Object, _ ByVal e As DetailsViewInsertedEventArgs) _ Handles CustomerDetailsView.ItemInserted ' Use the Exception property to determine whether an exception ' occurred during the insert operation. If e.Exception Is Nothing Then ' Use the Values property to get the value entered by ' the user for the CompanyName field. Dim name As String = e.Values("CompanyName").ToString() ' Display a confirmation message. MessageLabel.Text = name & " added successfully. " Else ' Insert the code to handle the exception. MessageLabel.Text = e.Exception.Message ' Use the ExceptionHandled property to indicate that the ' exception is already handled. e.ExceptionHandled = True ' When an exception occurs, keep the DetailsView ' control in insert mode. e.KeepInInsertMode = True End If End Sub </script> <html> <body> <form runat="server"> <h3>DetailsViewInsertedEventHandler Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogenerateinsertbutton="true" autogeneraterows="true" allowpaging="true" oniteminserted="CustomerDetailsView_ItemInserted" 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_ItemInserted(Object sender, DetailsViewInsertedEventArgs e) { // Use the Exception property to determine whether an exception // occurred during the insert operation. if (e.Exception == null) { // Use the Values property to get the value entered by // the user for the CompanyName field. String name = e.Values["CompanyName"].ToString(); // Display a confirmation message. MessageLabel.Text = name + " added successfully. "; } else { // Insert the code to handle the exception. MessageLabel.Text = e.Exception.Message; // Use the ExceptionHandled property to indicate that the // exception is already handled. e.ExceptionHandled = true; // When an exception occurs, keep the DetailsView // control in insert mode. e.KeepInInsertMode = true; } } </script> <html> <body> <form runat="server"> <h3>DetailsViewInsertedEventHandler Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogenerateinsertbutton="true" autogeneraterows="true" allowpaging="true" oniteminserted="CustomerDetailsView_ItemInserted" 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>

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


Weblioに収録されているすべての辞書からDetailsViewInsertedEventHandler デリゲートを検索する場合は、下記のリンクをクリックしてください。

- DetailsViewInsertedEventHandler デリゲートのページへのリンク