DetailsViewInsertEventArgs クラスとは? わかりやすく解説

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

DetailsViewInsertEventArgs クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

ItemInserting イベントデータ提供します

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

Public Class DetailsViewInsertEventArgs
    Inherits CancelEventArgs
Dim instance As DetailsViewInsertEventArgs
public class DetailsViewInsertEventArgs : CancelEventArgs
public ref class DetailsViewInsertEventArgs
 : public CancelEventArgs
public class DetailsViewInsertEventArgs extends
 CancelEventArgs
public class DetailsViewInsertEventArgs extends
 CancelEventArgs
解説解説

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>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.EventArgs
     System.ComponentModel.CancelEventArgs
      System.Web.UI.WebControls.DetailsViewInsertEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DetailsViewInsertEventArgs メンバ
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewInsertEventHandler
CancelEventArgs
DetailsView.ItemInserting イベント
Cancel
CommandArgument
Values



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

辞書ショートカット

すべての辞書の索引

「DetailsViewInsertEventArgs クラス」の関連用語

DetailsViewInsertEventArgs クラスのお隣キーワード
検索ランキング

   

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



DetailsViewInsertEventArgs クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS