GridViewDeleteEventArgs.Keys プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > GridViewDeleteEventArgs.Keys プロパティの意味・解説 

GridViewDeleteEventArgs.Keys プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

削除する行の主キーを表すフィールドの名前と値のペアのディクショナリを取得します

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

Dim instance As GridViewDeleteEventArgs
Dim value As IOrderedDictionary

value = instance.Keys
public IOrderedDictionary Keys { get; }
public:
property IOrderedDictionary^ Keys {
    IOrderedDictionary^ get ();
}
/** @property */
public IOrderedDictionary get_Keys ()
public function get Keys
 () : IOrderedDictionary

プロパティ
削除する行の主キーを表すフィールドの名前と値のペアが格納された System.Collections.Specialized.IOrderedDictionary オブジェクト

解説解説

GridView コントロールの DataKeyNames プロパティ設定されている場合Keys プロパティ (ディクショナリ) を使用して、行の削除する 1 つ上の主キーの値にアクセスます。

メモメモ

キー以外のフィールドの値にアクセスするには、Values プロパティ使用します

Keys ディクショナリには、DataKeyNames プロパティ指定され1 つ上のフィールドの名前と値のペアが自動的に格納されます。主キー複数フィールド構成されている場合キー フィールドごとに別のエントリが Keys ディクショナリに追加されます。

キー フィールドの名前を確認するには、Keys ディクショナリに格納されている System.Collections.DictionaryEntry オブジェクトの DictionaryEntry.Key プロパティ使用しますキー フィールドの値を確認するには、DictionaryEntry.Value プロパティ使用します

使用例使用例

Values プロパティ使用して削除する行のキー フィールドの値にアクセスする方法次の例に示しますその後削除されレコードログ ファイルに値が書き込まれます。

<%@ Page language="VB" %>
<%@ import namespace="System.IO"
 %>

<script runat="server">

  Sub CustomersGridView_RowDeleting(ByVal sender
 As Object, ByVal e As
 GridViewDeleteEventArgs)

    ' Record the delete operation in a log file.

    ' Create the log text. 
    Dim logText As String
 = ""

    ' Append the values of the key fields to the log text.
    Dim i As Integer
    For i = 0 To e.Keys.Count - 1
    
      logText &= e.Keys(i).ToString() & ";"
      
    Next

    ' Append the values of the non-key fields to the log text.
    For i = 0 To e.Values.Count - 1
    
      If e.Values(i) IsNot Nothing Then
        logText &= e.Values(i).ToString() & ";"
      Else
        logText &= "Nothing" & ";"
      End If
      
    Next
    
    ' Display the log content.
    LogTextLabel.Text = logText

    ' Append the text to a log file.
    Try
    
      Dim sw As StreamWriter
      sw = File.AppendText(Server.MapPath(Nothing) & "\deletelog.txt")
      sw.WriteLine(logText)
      sw.Flush()
      sw.Close()
    
    Catch ex As UnauthorizedAccessException
    
      ' You must provide read/write access to the file using ACLs.
      LogErrorLabel.Text = "You do not have permission to write
 to the log."
    
    End Try

  End Sub
    
  Sub CustomersGridView_RowDeleted(ByVal sender
 As Object, ByVal e As
 GridViewDeletedEventArgs)
    
    If e.Exception Is Nothing
 Then
    
      ' The delete operation succeeded. Clear the message label.
      Message.Text = ""
    
    Else
    
      ' The delete operation failed. Display an error message.
      Message.Text = e.AffectedRows.ToString() & " rows deleted.
 " & e.Exception.Message
      e.ExceptionHandled = True
      
    End If
        
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewDeleteEventArgs Keys and Values Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>
        
      <br/>
      
      <asp:label id="LogTextLabel"
        forecolor="Red"          
        runat="server"/>
        
      <br/>
        
      <asp:label id="LogErrorLabel"
        forecolor="Red"          
        runat="server"/>
                
      <br/>

      <asp:gridview id="CustomersGridView" 
        allowpaging="true"
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogeneratedeletebutton="true" 
        datakeynames="CustomerID"
        onrowdeleted="CustomersGridView_RowDeleted"
        onrowdeleting="CustomersGridView_RowDeleting"
   
        runat="server">
        
      </asp:gridview>
            
      <!-- 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="CustomersSqlDataSource"
  
        selectcommand="Select [CustomerID], [CompanyName], [Address],
 [City], [PostalCode], [Country] From [Customers]"
        deletecommand="Delete from Customers where CustomerID
 = @CustomerID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

<%@ Page language="C#" %>
<%@ import namespace="System.IO" %>

<script runat="server">

  void CustomersGridView_RowDeleting(Object sender, GridViewDeleteEventArgs
 e)
  {

    // Record the delete operation in a log file.

    // Create the log text. 
    String logText = "";

    // Append the values of the key fields to the log text.
    foreach (DictionaryEntry keyEntry in e.Keys)
    {
      logText += keyEntry.Key + "=" + keyEntry.Value + ";";
    }

    // Append the values of the non-key fields to the log text.
    foreach (DictionaryEntry valueEntry in
 e.Values)
    {
      logText += valueEntry.Key + "=" + valueEntry.Value + ";";
    }

    // Display the log content.
    LogTextLabel.Text = logText;
    
    // Append the text to a log file.
    try
    {
      StreamWriter sw;
      sw = File.AppendText(Server.MapPath(null) + "\\deletelog.txt");
      sw.WriteLine(logText);
      sw.Flush();
      sw.Close();
    }
    catch(UnauthorizedAccessException ex)
    {
      // You must provide read/write access to the file using ACLs.
      LogErrorLabel.Text = "You do not have permission to write to the log.";
    }

  }
    
  void CustomersGridView_RowDeleted(Object sender, GridViewDeletedEventArgs
 e)
  {
    
    if (e.Exception == null)
    {
      // The delete operation succeeded. Clear the message label.
      Message.Text = "";
    }
    else
    {
      // The delete operation failed. Display an error message.
      Message.Text = e.AffectedRows.ToString() + " rows deleted. " + e.Exception.Message;
      e.ExceptionHandled = true;
    }
        
  }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewDeleteEventArgs Keys and Values Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>
        
      <br/>
      
      <asp:label id="LogTextLabel"
        forecolor="Red"          
        runat="server"/>
        
      <br/>
        
      <asp:label id="LogErrorLabel"
        forecolor="Red"          
        runat="server"/>
                
      <br/>

      <asp:gridview id="CustomersGridView" 
        allowpaging="true"
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogeneratedeletebutton="true" 
        datakeynames="CustomerID"
        onrowdeleted="CustomersGridView_RowDeleted"
        onrowdeleting="CustomersGridView_RowDeleting"   
        runat="server">
        
      </asp:gridview>
            
      <!-- 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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
        deletecommand="Delete from Customers where CustomerID = @CustomerID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GridViewDeleteEventArgs クラス
GridViewDeleteEventArgs メンバ
System.Web.UI.WebControls 名前空間
Values
GridView.DataKeyNames プロパティ
System.Collections.Specialized.IOrderedDictionary
DictionaryEntry.Key
DictionaryEntry.Value


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

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

辞書ショートカット

すべての辞書の索引

「GridViewDeleteEventArgs.Keys プロパティ」の関連用語

GridViewDeleteEventArgs.Keys プロパティのお隣キーワード
検索ランキング

   

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



GridViewDeleteEventArgs.Keys プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS