GridViewUpdateEventArgs クラス

定義

RowUpdating イベントのデータを提供します。

public ref class GridViewUpdateEventArgs : System::ComponentModel::CancelEventArgs
public class GridViewUpdateEventArgs : System.ComponentModel.CancelEventArgs
type GridViewUpdateEventArgs = class
    inherit CancelEventArgs
Public Class GridViewUpdateEventArgs
Inherits CancelEventArgs
継承
GridViewUpdateEventArgs

次の例では、イベント処理メソッドに渡された オブジェクトを使用 GridViewUpdateEventArgs して、データ ソースを更新する前にユーザーが指定したすべての値を HTML エンコードする方法を示します。


<%@ Page language="C#" %>

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

  void CustomersGridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
  {
     
    // Iterate through the NewValues collection and HTML encode all 
    // user-provided values before updating the data source.
    foreach (DictionaryEntry entry in e.NewValues)
    {
    
      e.NewValues[entry.Key] = Server.HtmlEncode(entry.Value.ToString());
    
    }
        
  }
       
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView RowUpdating Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView RowUpdating Example</h3>
            
      <!-- The GridView control automatically sets the columns     -->
      <!-- specified in the datakeynames property as read-only.    -->
      <!-- No input controls are rendered for these columns in     -->
      <!-- edit mode.                                              -->
      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogenerateeditbutton="true"
        allowpaging="true" 
        datakeynames="CustomerID"
        onrowupdating="CustomersGridView_RowUpdating"  
        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]"
        updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country WHERE (CustomerID = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

<%@ Page language="VB" %>

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

  Sub CustomersGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    
    ' Use the CopyTo method to copy the DictionaryEntry objects in the 
    ' NewValues collection to an array.
    Dim records(e.NewValues.Count - 1) As DictionaryEntry
    e.NewValues.CopyTo(records, 0)
    
    ' Iterate through the array and HTML encode all user-provided values 
    ' before updating the data source.
    Dim entry As DictionaryEntry
    For Each entry In records
            
      e.NewValues(entry.Key) = Server.HtmlEncode(entry.Value.ToString())
      
    Next
        
  End Sub
       
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView RowUpdating Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView RowUpdating Example</h3>
            
      <!-- The GridView control automatically sets the columns     -->
      <!-- specified in the datakeynames property as read-only.    -->
      <!-- No input controls are rendered for these columns in     -->
      <!-- edit mode.                                              -->
      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogenerateeditbutton="true"
        allowpaging="true" 
        datakeynames="CustomerID"
        onrowupdating="CustomersGridView_RowUpdating"  
        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]"
        updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country WHERE (CustomerID = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

注釈

コントロールは GridView 、行の RowUpdating [更新] ボタンがクリックされたときに、コントロールが行を更新する GridView 前にイベントを発生させます。 これにより、このイベントが発生するたびに、更新操作のキャンセルなどのカスタム ルーチンを実行するイベント処理メソッドを提供できます。

GridViewUpdateEventArgsオブジェクトはイベント処理メソッドに渡されます。これにより、現在の行のインデックスを決定し、更新操作を取り消す必要があることを示すことができます。 更新操作を取り消すには、 オブジェクトの プロパティを CancelGridViewUpdateEventArgstrue設定します。 必要に応じて、値がKeysOldValuesデータ ソースに渡される前に、および NewValues コレクションを操作することもできます。 これらのコレクションを使用する一般的な方法は、ユーザーが指定した値をデータ ソースに格納する前に HTML エンコードすることです。 これは、スクリプトインジェクション攻撃を防ぐのに役立ちます。

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。

のインスタンスの初期プロパティ値の GridViewUpdateEventArgs一覧については、 コンストラクターを GridViewSelectEventArgs 参照してください。

コンストラクター

GridViewUpdateEventArgs(Int32)

GridViewUpdateEventArgs クラスの新しいインスタンスを初期化します。

プロパティ

Cancel

イベントをキャンセルするかどうかを示す値を取得または設定します。

(継承元 CancelEventArgs)
Keys

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

NewValues

更新する行のキー以外のフィールドの名前と値のペアの改訂後の値が格納されているディクショナリを取得します。

OldValues

更新する行の元のフィールドの名前と値のペアが格納されているディクショナリを取得します。

RowIndex

更新される行インデックスを取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください