DetailsView.ItemInserted イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DetailsView.ItemInserted イベントの意味・解説 

DetailsView.ItemInserted イベント

メモ : このイベントは、.NET Framework version 2.0新しく追加されたものです。

DetailsView コントロール内の Insert ボタンクリックされた場合に、挿入操作後に発生します

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

Public Event ItemInserted As
 DetailsViewInsertedEventHandler
Dim instance As DetailsView
Dim handler As DetailsViewInsertedEventHandler

AddHandler instance.ItemInserted, handler
public event DetailsViewInsertedEventHandler ItemInserted
public:
event DetailsViewInsertedEventHandler^ ItemInserted {
    void add (DetailsViewInsertedEventHandler^ value);
    void remove (DetailsViewInsertedEventHandler^ value);
}
/** @event */
public void add_ItemInserted (DetailsViewInsertedEventHandler
 value)

/** @event */
public void remove_ItemInserted (DetailsViewInsertedEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

ItemInserted イベント使用してDetailsView コントロール挿入操作実行した後で GridView コントロール最新表示する方法コード例次に示します。これにより、GridView コントロールは常に DetailsView コントロール同期されます

<%@ Page Language="VB" %>

<script runat="server">
  Sub CustomerDetail_ItemInserted(ByVal sender
 As Object, _
    ByVal e As DetailsViewInsertedEventArgs)
    ' Refresh the GridView control after a new record is inserted in
 
    ' the DetailsView control.
    CustomersView.DataBind()
  End Sub
  
  Sub CustomerDetail_ItemInserting(ByVal sender
 As Object, _
    ByVal e As DetailsViewInsertEventArgs)
    ' Iterate though the values entered by the user and HTML encode
 
    ' the values. This helps prevent malicious values from being 
    ' stored in the data source.
    For i As Integer = 0
 To e.Values.Count - 1
      If e.Values(i) IsNot Nothing Then
        e.Values(i) = Server.HtmlEncode(e.Values(i).ToString())
      End If
    Next
  End Sub
  
  Sub CustomerDetail_ItemUpdated(ByVal sender
 As Object, _
    ByVal e As DetailsViewUpdatedEventArgs)
    ' Refresh the GridView control after a new record is updated 
    ' in the DetailsView control.
    CustomersView.DataBind()
  End Sub
  
  Sub CustomerDetail_ItemUpdating(ByVal sender
 As Object, _
    ByVal e As DetailsViewUpdateEventArgs)
    ' Iterate though the values entered by the user and HTML encode
 
    ' the values. This helps prevent malicious values from being 
    ' stored in the data source.
    For i As Integer = 0
 To e.NewValues.Count - 1
      If e.NewValues(i) IsNot Nothing Then
        e.NewValues(i) = Server.HtmlEncode(e.NewValues(i).ToString())
      End If
    Next
  End Sub
  
  Sub CustomerDetail_ItemDeleted(ByVal sender
 As Object, _
    ByVal e As DetailsViewDeletedEventArgs)
    ' Refresh the GridView control after a new record is updated 
    ' in the DetailsView control.
    CustomersView.DataBind()
  End Sub
</script>

<html>
<body>
  <form id="Form1" runat="server">
    <h3>DetailsView Example</h3>
    <table cellspacing="10">
      <tr>
        <td>
          <!-- Use a GridView control in combination with
      -->
          <!-- a DetailsView control to display master-detail
  -->
          <!-- information. When the user selects a store from
 -->
          <!-- GridView control, the customers's detailed      -->
          <!-- information is displayed in
 the DetailsView     -->
          <!-- control.                                        -->
          <asp:GridView ID="CustomersView" DataSourceID="Customers"
 
            AutoGenerateColumns="False"
            DataKeyNames="CustomerID" runat="server">
            <HeaderStyle BackColor="Blue" ForeColor="White"
 />
            <Columns>
              <asp:CommandField ShowSelectButton="True"
 />
              <asp:BoundField DataField="ContactName"
 
                HeaderText="ContactName" />
              <asp:BoundField DataField="CompanyName"
 
                HeaderText="CompanyName" />
            </Columns>
          </asp:GridView>
        </td>
        <td valign="top">
          <asp:DetailsView ID="CustomerDetail"
 DataSourceID="Details" 
            AutoGenerateRows="false"
            AutoGenerateInsertButton="true" 
            AutoGenerateEditButton="true" 
            AutoGenerateDeleteButton="true"
            EmptyDataText="No records." 
            DataKeyNames="CustomerID" GridLines="Both"
 
            OnItemInserted="CustomerDetail_ItemInserted"
            OnItemInserting="CustomerDetail_ItemInserting"
 
            OnItemUpdated="CustomerDetail_ItemUpdated"
            OnItemUpdating="CustomerDetail_ItemUpdating"
 
            OnItemDeleted="CustomerDetail_ItemDeleted"
            runat="server">
            <HeaderStyle BackColor="Navy" ForeColor="White"
 />
            <RowStyle BackColor="White" />
            <AlternatingRowStyle BackColor="LightGray"
 />
            <EditRowStyle BackColor="LightCyan"
 />
            <Fields>
              <asp:BoundField DataField="CustomerID"
 HeaderText="CustomerID" 
                ReadOnly="True"
 />
              <asp:BoundField DataField="ContactName"
 HeaderText="ContactName" />
              <asp:BoundField DataField="ContactTitle"
 HeaderText="ContactTitle" />
              <asp:BoundField DataField="CompanyName"
 HeaderText="CompanyName" />
              <asp:BoundField DataField="Address"
 HeaderText="Address" />
              <asp:BoundField DataField="City"
 HeaderText="City" />
              <asp:BoundField DataField="Region"
 HeaderText="Region" />
              <asp:BoundField DataField="PostalCode"
 HeaderText="PostalCode" />
              <asp:BoundField DataField="Country"
 HeaderText="Country" />
              <asp:BoundField DataField="Phone"
 HeaderText="Phone" />
              <asp:BoundField DataField="Fax" HeaderText="Fax"
 />
            </Fields>
          </asp:DetailsView>
        </td>
      </tr>
    </table>
    <!-- This example uses Microsoft SQL Server and connects
 -->
    <!-- to the Northwind sample database.                
   -->
    <!-- It is strongly recommended that each
 data-bound     -->
    <!-- control uses a separate data source control.        -->
    <asp:SqlDataSource ID="Customers" runat="server"
 
      ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
      SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] 
        FROM [Customers]">
    </asp:SqlDataSource>
    <!-- Add a filter to the data source control for
 the     -->
    <!-- DetailsView control to display the details of
 the   -->
    <!-- store selected in the GridView control.          
   -->
    <asp:SqlDataSource ID="Details" 
      ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
      runat="server" 
      SelectCommand="SELECT * FROM [Customers] 
        WHERE ([CustomerID] = @CustomerID)"
      DeleteCommand="DELETE FROM [Customers] 
        WHERE [CustomerID] = @CustomerID"
      InsertCommand="INSERT INTO [Customers] ([CustomerID], 
        [CompanyName], [ContactName], [ContactTitle], [Address], 
        [City], [Region], [PostalCode], [Country], [Phone], [Fax]) 
        VALUES (@CustomerID, @CompanyName, @ContactName, 
        @ContactTitle, @Address, @City, @Region, @PostalCode, 
        @Country, @Phone, @Fax)"
      UpdateCommand="UPDATE [Customers] SET 
        [CompanyName] = @CompanyName, 
        [ContactName] = @ContactName, [ContactTitle] = @ContactTitle, 
        [Address] = @Address, [City] = @City, [Region] = @Region, 
        [PostalCode] = @PostalCode, [Country] = @Country, 
        [Phone] = @Phone, [Fax] = @Fax 
        WHERE [CustomerID] = @CustomerID">
      <SelectParameters>
        <asp:ControlParameter ControlID="CustomersView"
 
          Name="CustomerID" PropertyName="SelectedValue"
          Type="String" />
      </SelectParameters>
      <DeleteParameters>
        <asp:Parameter Name="CustomerID" Type="String"
 />
      </DeleteParameters>
      <UpdateParameters>
        <asp:Parameter Name="CompanyName" Type="String"
 />
        <asp:Parameter Name="ContactName" Type="String"
 />
        <asp:Parameter Name="ContactTitle" Type="String"
 />
        <asp:Parameter Name="Address" Type="String"
 />
        <asp:Parameter Name="City" Type="String"
 />
        <asp:Parameter Name="Region" Type="String"
 />
        <asp:Parameter Name="PostalCode" Type="String"
 />
        <asp:Parameter Name="Country" Type="String"
 />
        <asp:Parameter Name="Phone" Type="String"
 />
        <asp:Parameter Name="Fax" Type="String"
 />
        <asp:Parameter Name="CustomerID" Type="String"
 />
      </UpdateParameters>
      <InsertParameters>
        <asp:Parameter Name="CustomerID" Type="String"
 />
        <asp:Parameter Name="CompanyName" Type="String"
 />
        <asp:Parameter Name="ContactName" Type="String"
 />
        <asp:Parameter Name="ContactTitle" Type="String"
 />
        <asp:Parameter Name="Address" Type="String"
 />
        <asp:Parameter Name="City" Type="String"
 />
        <asp:Parameter Name="Region" Type="String"
 />
        <asp:Parameter Name="PostalCode" Type="String"
 />
        <asp:Parameter Name="Country" Type="String"
 />
        <asp:Parameter Name="Phone" Type="String"
 />
        <asp:Parameter Name="Fax" Type="String"
 />
      </InsertParameters>
    </asp:SqlDataSource>
  </form>
</body>
</html>
<%@ Page Language="C#" %>

<script runat="server">
  void CustomerDetail_ItemInserted(object sender, 
    DetailsViewInsertedEventArgs e)
  {
    // Refresh the GridView control after a new record is inserted 
    // in the DetailsView control.
    CustomersView.DataBind();
  }

  void CustomerDetail_ItemInserting(object sender, 
    DetailsViewInsertEventArgs e)
  {
    // Iterate though the values entered by the user and HTML encode
 
    // the values. This helps prevent malicious values from being 
    // stored in the data source.
    for (int i = 0; i < e.Values.Count;
 i++)
    {
      if (e.Values[i] != null)
      {
        e.Values[i] = Server.HtmlEncode(e.Values[i].ToString());
      }
    }
  }

  void CustomerDetail_ItemUpdated(object sender, 
    DetailsViewUpdatedEventArgs e)
  {
    // Refresh the GridView control after a new record is updated 
    // in the DetailsView control.
    CustomersView.DataBind();
  }

  void CustomerDetail_ItemUpdating(object sender, 
    DetailsViewUpdateEventArgs e)
  {
    // Iterate though the values entered by the user and HTML encode
 
    // the values. This helps prevent malicious values from being 
    // stored in the data source.
    for (int i = 0; i < e.NewValues.Count;
 i++)
    {
      if (e.NewValues[i] != null)
      {
        e.NewValues[i] = Server.HtmlEncode(e.NewValues[i].ToString());
      }
    }
  }

  void CustomerDetail_ItemDeleted(object sender, 
    DetailsViewDeletedEventArgs e)
  {
    // Refresh the GridView control after a new record is updated 
    // in the DetailsView control.
    CustomersView.DataBind();
  }
</script>

<html>
<body>
  <form id="Form1" runat="server">
    <h3>
      DetailsView Example</h3>
    <table cellspacing="10">
      <tr>
        <td>
          <!-- Use a GridView control in combination with 
     -->
          <!-- a DetailsView control to display master-detail  -->
          <!-- information. When the user selects a store from -->
          <!-- GridView control, the customers//s detailed     -->
          <!-- information is displayed in the DetailsView
     -->
          <!-- control.                                        -->
          <asp:GridView ID="CustomersView" DataSourceID="Customers"
 
            AutoGenerateColumns="False"
            DataKeyNames="CustomerID" runat="server">
            <HeaderStyle BackColor="Blue" ForeColor="White"
 />
            <Columns>
              <asp:CommandField ShowSelectButton="True" />
              <asp:BoundField DataField="ContactName" 
                HeaderText="ContactName" />
              <asp:BoundField DataField="CompanyName" 
                HeaderText="CompanyName" />
            </Columns>
          </asp:GridView>
        </td>
        <td valign="top">
          <asp:DetailsView ID="CustomerDetail" 
            DataSourceID="Details" AutoGenerateRows="false"
            AutoGenerateInsertButton="true" 
            AutoGenerateEditButton="true" 
            AutoGenerateDeleteButton="true"
            EmptyDataText="No records." 
            DataKeyNames="CustomerID" GridLines="Both" 
            OnItemInserted="CustomerDetail_ItemInserted"
            OnItemInserting="CustomerDetail_ItemInserting" 
            OnItemUpdated="CustomerDetail_ItemUpdated"
            OnItemUpdating="CustomerDetail_ItemUpdating" 
            OnItemDeleted="CustomerDetail_ItemDeleted"
            runat="server">
            <HeaderStyle BackColor="Navy" ForeColor="White"
 />
            <RowStyle BackColor="White" />
            <AlternatingRowStyle BackColor="LightGray" />
            <EditRowStyle BackColor="LightCyan" />
            <Fields>
              <asp:BoundField DataField="CustomerID" HeaderText="CustomerID"
 ReadOnly="True" />
              <asp:BoundField DataField="ContactName" HeaderText="ContactName"
 />
              <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle"
 />
              <asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
 />
              <asp:BoundField DataField="Address" HeaderText="Address"
 />
              <asp:BoundField DataField="City" HeaderText="City"
 />
              <asp:BoundField DataField="Region" HeaderText="Region"
 />
              <asp:BoundField DataField="PostalCode" HeaderText="PostalCode"
 />
              <asp:BoundField DataField="Country" HeaderText="Country"
 />
              <asp:BoundField DataField="Phone" HeaderText="Phone"
 />
              <asp:BoundField DataField="Fax" HeaderText="Fax"
 />
            </Fields>
          </asp:DetailsView>
        </td>
      </tr>
    </table>
    <!-- This example uses Microsoft SQL Server and connects -->
    <!-- to the Northwind sample database.                   -->
    <!-- It is strongly recommended that each data-bound     -->
    <!-- control uses a separate data source control.        -->
    <asp:SqlDataSource ID="Customers" runat="server" 
      ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
      SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] 
        FROM [Customers]">
    </asp:SqlDataSource>
    <!-- Add a filter to the data source control for the  
   -->
    <!-- DetailsView control to display the details of the   -->
    <!-- store selected in the GridView control.          
   -->
    <asp:SqlDataSource ID="Details" 
      ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
      runat="server" 
      SelectCommand="SELECT * FROM [Customers] 
        WHERE ([CustomerID] = @CustomerID)"
      DeleteCommand="DELETE FROM [Customers] 
        WHERE [CustomerID] = @CustomerID"
      InsertCommand="INSERT INTO [Customers] ([CustomerID], 
        [CompanyName], [ContactName], [ContactTitle], [Address], 
        [City], [Region], [PostalCode], [Country], [Phone], [Fax]) 
        VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, 
        @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax)"
      UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, 
        [ContactName] = @ContactName, [ContactTitle] = @ContactTitle, 
        [Address] = @Address, [City] = @City, [Region] = @Region, 
        [PostalCode] = @PostalCode, [Country] = @Country, 
        [Phone] = @Phone, [Fax] = @Fax 
        WHERE [CustomerID] = @CustomerID">
      <SelectParameters>
        <asp:ControlParameter ControlID="CustomersView" 
          Name="CustomerID" PropertyName="SelectedValue"
          Type="String" />
      </SelectParameters>
      <DeleteParameters>
        <asp:Parameter Name="CustomerID" Type="String" />
      </DeleteParameters>
      <UpdateParameters>
        <asp:Parameter Name="CompanyName" Type="String" />
        <asp:Parameter Name="ContactName" Type="String" />
        <asp:Parameter Name="ContactTitle" Type="String" />
        <asp:Parameter Name="Address" Type="String" />
        <asp:Parameter Name="City" Type="String" />
        <asp:Parameter Name="Region" Type="String" />
        <asp:Parameter Name="PostalCode" Type="String" />
        <asp:Parameter Name="Country" Type="String" />
        <asp:Parameter Name="Phone" Type="String" />
        <asp:Parameter Name="Fax" Type="String" />
        <asp:Parameter Name="CustomerID" Type="String" />
      </UpdateParameters>
      <InsertParameters>
        <asp:Parameter Name="CustomerID" Type="String" />
        <asp:Parameter Name="CompanyName" Type="String" />
        <asp:Parameter Name="ContactName" Type="String" />
        <asp:Parameter Name="ContactTitle" Type="String" />
        <asp:Parameter Name="Address" Type="String" />
        <asp:Parameter Name="City" Type="String" />
        <asp:Parameter Name="Region" Type="String" />
        <asp:Parameter Name="PostalCode" Type="String" />
        <asp:Parameter Name="Country" Type="String" />
        <asp:Parameter Name="Phone" Type="String" />
        <asp:Parameter Name="Fax" Type="String" />
      </InsertParameters>
    </asp:SqlDataSource>
  </form>
</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DetailsView クラス
DetailsView メンバ
System.Web.UI.WebControls 名前空間
DetailsViewInsertedEventArgs
ExceptionHandled
KeepInInsertMode
ItemInserting
OnItemInserted
その他の技術情報
イベント利用


このページでは「.NET Framework クラス ライブラリ リファレンス」からDetailsView.ItemInserted イベントを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDetailsView.ItemInserted イベントを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDetailsView.ItemInserted イベント を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DetailsView.ItemInserted イベント」の関連用語

DetailsView.ItemInserted イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DetailsView.ItemInserted イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS