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

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

GridViewDeleteEventArgs.RowIndex プロパティ

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

削除される行のインデックス取得します

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

Dim instance As GridViewDeleteEventArgs
Dim value As Integer

value = instance.RowIndex
public int RowIndex { get;
 }
public:
property int RowIndex {
    int get ();
}
/** @property */
public int get_RowIndex ()

プロパティ
削除される行の 0 から始まるインデックス

解説解説
使用例使用例

RowIndex プロパティ使用して削除する行のインデックス確認する方法次の例に示します

<%@ Page language="VB" %>

<script runat="server">

  Sub CustomersGridView_RowDeleting(ByVal sender
 As Object, ByVal e As
 GridViewDeleteEventArgs)
        
    ' Get the country/region of the record being deleted.
    Dim row As GridViewRow = CustomersGridView.Rows(e.RowIndex)
    Dim region As String
 = row.Cells(6).Text
    
    ' Cancel the delete operation if the country/region is "USA".
    If region = "USA" Then
    
      e.Cancel = True
      Message.Text = "You cannot delete a record from "
 & region & "."
      
    End If
    
  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 = "An error occurred during the delete operation.
 " & _
        e.AffectedRows.ToString() & " rows deleted."
      e.ExceptionHandled = true
        
    End If
    
  End Sub
  
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewDeleteEventArgs RowIndex Example</h3>
            
      <asp:label id="Message"
        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#" %>

<script runat="server">

  void CustomersGridView_RowDeleting(Object sender, GridViewDeleteEventArgs
 e)
  {
    
    // Get the country/region of the record being deleted.
    GridViewRow row = CustomersGridView.Rows[e.RowIndex];
    String region = row.Cells[6].Text;
    
    // Cancel the delete operation if the country/region is "USA".
    if(region == "USA")
    {
      e.Cancel = true;
      Message.Text = "You cannot delete a record from " + region + ".";
    }
    
  }

  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 = "An error occurred during the delete operation. "
 +
        e.AffectedRows.ToString() + " rows deleted.";
    }
        
  }
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewDeleteEventArgs RowIndex Example</h3>
            
      <asp:label id="Message"
        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 名前空間
GridView クラス
GridView.Rows プロパティ


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS