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

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

GridViewUpdateEventArgs.Keys プロパティ

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

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

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

Dim instance As GridViewUpdateEventArgs
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 プロパティ (ディクショナリ) を使用して更新する行の主キーの値にアクセスます。

メモメモ

キー以外のフィールドの値にアクセスするには、NewValues プロパティまたは OldValues プロパティ使用しますNewValues プロパティには更新後の値が格納されOldValues プロパティには元の値が格納されます。

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

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

使用例使用例

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

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    Sub EmployeesGridView_RowUpdating(ByVal
 sender As Object, ByVal
 e As GridViewUpdateEventArgs)
    
        ' Record the update operation in a log file.
        
        ' Create the log text. 
        Dim logText As String
 = ""
        
        ' Append the key field values to the log text.
        Dim i As Integer
        
        For i = 0 To e.Keys.Count - 1
            
            logText += e.Keys(i) & ";"
            
        Next

        ' Append the text to a log file.
        Dim sw As StreamWriter
        sw = File.AppendText(Server.MapPath(Nothing) & "\updatelog.txt")
        sw.WriteLine(logText)
        sw.Flush()
        sw.Close()
    
    End Sub
    
    Sub EmployeesGridView_RowUpdated(ByVal
 sender As Object, ByVal
 e As GridViewUpdatedEventArgs)

        If e.Exception Is Nothing
 Then
            
            ' The update operation succeeded. Clear the message label.
            Message.Text = ""

        Else

            ' The update operation failed. Display an error message.
            Message.Text = e.AffectedRows.ToString() & " rows
 updated. " & e.Exception.Message
            e.ExceptionHandled = True
        
        End If
        
    End Sub

</script>

<html  >
<head runat="server">
    <title>GridViewUpdateEventArgs Keys Example</title>
</head>
<body>
        <form id="Form1" runat="server">
        
            <h3>GridViewUpdateEventArgs Keys Example</h3>
            
            <asp:label id="Message"
                 forecolor="Red"          
                 runat="server"/>
                
            <br/>

            <!-- The GridView control automatically sets the columns     -->
            <!-- specified in the datakeynames attribute as
 read-only.   -->
            <!-- No input controls are rendered for these columns
 in     -->
            <!-- edit mode.                                              -->
            <asp:gridview id="EmployeesGridView"
 
                datasourceid="EmployeesSqlDataSource"
                autogenerateeditbutton="True" 
                onrowupdating="EmployeesGridView_RowUpdating"
                onrowupdated="EmployeesGridView_RowUpdated"
   
                runat="server">
            </asp:gridview>
            
            <!-- This example uses Microsoft SQL Server and
 connects -->
            <!-- to the Northwind sample database.        
           -->
            <asp:sqldatasource id="EmployeesSqlDataSource"
  
                selectcommand="SELECT [EmployeeID], [LastName],
 [FirstName], [HireDate] FROM [Employees]"
                updatecommand="UPDATE [Employees] SET [LastName]
 = @LastName, [FirstName] = @FirstName, [HireDate] = @HireDate WHERE [EmployeeID]
 = @EmployeeID" 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString
 %>"
                runat="server" >
                <DeleteParameters>
                    <asp:Parameter Name="EmployeeID"
 Type="Int32" />
                </DeleteParameters>
            </asp:sqldatasource>
            
        </form>
    </body>
</html>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    void EmployeesGridView_RowUpdating(Object sender, GridViewUpdateEventArgs
 e)
    {
    
        // Record the update operation in a log file.
        
        // Create the log text. 
        String logText = "";
        
        // Append the key field values to the log text.
        foreach (DictionaryEntry keyEntry in
 e.Keys)
        {
            logText += keyEntry.Key + "=" + keyEntry.Value + ";";
        }
        
        // Append the text to a log file.
        StreamWriter sw;
        sw = File.AppendText(Server.MapPath(null) + "\\updatelog.txt");
        sw.WriteLine(logText);
        sw.Flush();
        sw.Close();
    
    }

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

</script>

<html  >
<head id="Head1" runat="server">
    <title>GridViewUpdateEventArgs Keys Example</title>
</head>
<body>
        <form id="Form1" runat="server">
        
            <h3>GridViewUpdateEventArgs Keys Example</h3>
            
            <asp:label id="Message"
                 forecolor="Red"          
                 runat="server"/>
                
            <br/>

            <!-- The GridView control automatically sets the columns     -->
            <!-- specified in the datakeynames attribute as
 read-only.   -->
            <!-- No input controls are rendered for these columns
 in     -->
            <!-- edit mode.                                              -->
            <asp:gridview id="EmployeesGridView" 
                datasourceid="EmployeesSqlDataSource"
                autogenerateeditbutton="True" 
                onrowupdating="EmployeesGridView_RowUpdating"
                onrowupdated="EmployeesGridView_RowUpdated"   
                runat="server">
            </asp:gridview>
            
            <!-- This example uses Microsoft SQL Server and connects -->
            <!-- to the Northwind sample database.                   -->
            <asp:sqldatasource id="EmployeesSqlDataSource"  
                selectcommand="SELECT [EmployeeID], [LastName], [FirstName],
 [HireDate] FROM [Employees]"
                updatecommand="UPDATE [Employees] SET [LastName] = @LastName,
 [FirstName] = @FirstName, [HireDate] = @HireDate WHERE [EmployeeID] = @EmployeeID"
 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString
 %>"
                runat="server" >
                <DeleteParameters>
                    <asp:Parameter Name="EmployeeID" Type="Int32"
 />
                </DeleteParameters>
            </asp:sqldatasource>
            
        </form>
    </body>
</html>

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


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS