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

GridView.Rows プロパティ

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

GridView コントロールデータ行を表す GridViewRow オブジェクトコレクション取得します

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

Public Overridable ReadOnly
 Property Rows As GridViewRowCollection
Dim instance As GridView
Dim value As GridViewRowCollection

value = instance.Rows
public virtual GridViewRowCollection Rows { get;
 }
public:
virtual property GridViewRowCollection^ Rows {
    GridViewRowCollection^ get ();
}
/** @property */
public GridViewRowCollection get_Rows ()
public function get Rows
 () : GridViewRowCollection

プロパティ
GridView コントロール内のすべてのデータ行が格納された GridViewRowCollection。

解説解説
使用例使用例

Rows コレクション使用してGridView コントロール編集中の行にアクセスする方法次のコード例示します。行が更新されると、正常に更新されたことを示すメッセージ表示されます。

<%@ Page language="VB" %>

<script runat="server">

  Sub CustomersGridView_RowCommand(ByVal sender
 As Object, ByVal e As
 GridViewCommandEventArgs)
    
    ' Clear the message label when the user enters edit mode.
    If e.CommandName = "Edit" Then
      Message.Text = ""
    End If
    
  End Sub
  
  Sub CustomersGridView_RowUpdated(ByVal sender
 As Object, ByVal e As
 GridViewUpdatedEventArgs)
   
    ' The update operation was successful. Retrieve the row being edited.
    Dim index As Integer
 = CustomersGridView.EditIndex
    Dim row As GridViewRow = CustomersGridView.Rows(index)
        
    ' Notify the user that the update was successful.
    Message.Text = "Updated record " & row.Cells(1).Text
 + "."
    
  End Sub

  Sub CustomersGridView_RowCancelingEdit(ByVal
 sender As Object, ByVal
 e As GridViewCancelEditEventArgs)
   
    ' The update operation was canceled. Display the appropriate message.
    Message.Text = "Update operation canceled."
    
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView Rows Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                
      <br/>    
            
      <!-- 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"
        allowpaging="true" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogenerateeditbutton="true"
        datakeynames="CustomerID"
        onrowcommand="CustomersGridView_RowCommand"
        onrowupdated="CustomersGridView_RowUpdated"
        onrowcancelingedit="CustomersGridView_RowCancelingEdit"
  
        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)"
        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_RowCommand(Object sender, GridViewCommandEventArgs
 e)
  {
    
    // Clear the message label when the user enters edit mode.
    if (e.CommandName == "Edit")
    {
      Message.Text = "";
    }
    
  }

  void CustomersGridView_RowUpdated(Object sender, GridViewUpdatedEventArgs
 e)
    {
   
        // The update operation was successful. Retrieve the row being
 edited.
        int index = CustomersGridView.EditIndex;
        GridViewRow row = CustomersGridView.Rows[index];
        
        // Notify the user that the update was successful.
        Message.Text = "Updated record " + row.Cells[1].Text + ".";
    
    }

  void CustomersGridView_RowCancelingEdit(Object sender, GridViewCancelEditEventArgs
 e)
    {
   
        // The update operation was canceled. Display the appropriate
 message.
        Message.Text = "Update operation canceled.";
    
    }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView Rows Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                
      <br/>    
            
      <!-- 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"
        allowpaging="true" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogenerateeditbutton="true"
        datakeynames="CustomerID"
        onrowcommand="CustomersGridView_RowCommand"
        onrowupdated="CustomersGridView_RowUpdated"
        onrowcancelingedit="CustomersGridView_RowCancelingEdit"  
        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)"
        deletecommand="Delete from Customers where CustomerID = @CustomerID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GridView クラス
GridView メンバ
System.Web.UI.WebControls 名前空間
GridViewRow
GridViewRowCollection


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

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

辞書ショートカット

すべての辞書の索引

「GridView.Rows プロパティ」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS