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

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

GridViewRowCollection.Item プロパティ

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

指定したインデックス位置にある GridViewRow オブジェクト取得します

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

解説解説
使用例使用例

インデクサ使用してコレクションから GridViewRow オブジェクト取得する方法次の例に示しますGridViewRow オブジェクト内のセルの値がページ表示されます。

<%@ Page language="VB" %>

<script runat="server">
  
  Sub AuthorsGridView_RowUpdating(ByVal sender
 As Object, ByVal e As
 GridViewUpdateEventArgs)
    
    ' The GridView control does not automatically extract updated values
 
    ' from TemplateField column fields. These values must be added manually
 
    ' to the NewValues dictionary.
    
    ' Get the GridViewRow object that represents the row being edited
    ' from the Rows collection of the GridView control.
    Dim index As Integer
 = AuthorsGridView.EditIndex
    Dim row As GridViewRow = AuthorsGridView.Rows(index)
    
    ' Get the controls that contain the updated values. In this
    ' example, the updated values are contained in the TextBox 
    ' controls declared in the EditItemTemplates of the TemplateField
 
    ' column fields in the GridView control.
    Dim lastName As TextBox = CType(row.FindControl("LastNameTextBox"),
 TextBox)
    Dim firstName As TextBox = CType(row.FindControl("FirstNameTextBox"),
 TextBox)
    
    ' Add the updated values to the NewValues dictionary. Use the
    ' parameter names declared in the parameterized update query 
    ' string for the key names.
    e.NewValues("au_lname") = lastName.Text
    e.NewValues("au_fname") = firstName.Text
          
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRowCollection Indexer Example</h3>

      <!-- 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="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        autogenerateeditbutton="true"
        datakeynames="au_id"
        cellpadding="10"
        onrowupdating="AuthorsGridView_RowUpdating"
      
        runat="server">
                
        <columns>
        
          <asp:boundfield datafield="au_id"
            headertext="Author ID"
            readonly="true"/>
            
          <asp:templatefield headertext="Last Name"
            itemstyle-verticalalign="Top">
            
            <itemtemplate>
              <%#Eval("au_lname")%>
            </itemtemplate>
            
            <edititemtemplate>
              <asp:textbox id="LastNameTextBox"
                text='<%#Eval("au_lname")%>'
                width="90"
                runat="server"/>
              <br/>
              <asp:requiredfieldvalidator id="LastNameRequiredValidator"
                controltovalidate="LastNameTextBox"
                display="Dynamic"
                text="Please enter a last name." 
                runat="server" />             
                         
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:templatefield headertext="First Name"
            itemstyle-verticalalign="Top">
            
            <itemtemplate>
              <%#Eval("au_fname")%>
            </itemtemplate>
            
            <edititemtemplate>
              <asp:textbox id="FirstNameTextBox"
                text='<%#Eval("au_fname")%>'
                width="90"
                runat="server"/>
              <br/>
              <asp:requiredfieldvalidator id="FirstNameRequiredValidator"
                controltovalidate="FirstNameTextBox"
                display="Dynamic"
                text="Please enter a first name."
                runat="server" />             
         
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:checkboxfield datafield="contract"
 
            headertext="Contract"
            readonly="true"/>
            
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects
 -->
      <!-- to the Pubs sample database.                   
      -->
      <asp:sqldatasource id="AuthorsSqlDataSource"
  
        selectcommand="SELECT [au_id], [au_lname], [au_fname],
 [contract] FROM [authors]"             
        updatecommand="UPDATE authors SET au_lname=@au_lname,
 au_fname=@au_fname WHERE (authors.au_id = @au_id)" 
        connectionstring="server=localhost;database=pubs;integrated
 security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

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

<script runat="server">
  
  void AuthorsGridView_RowUpdating (Object sender, GridViewUpdateEventArgs
 e)
  {
    
    // The GridView control does not automatically extract updated values
 
    // from TemplateField column fields. These values must be added
 manually 
    // to the NewValues dictionary.
    
    // Get the GridViewRow object that represents the row being edited
    // from the Rows collection of the GridView control.
    int index = AuthorsGridView.EditIndex;
    GridViewRow row = AuthorsGridView.Rows[index];
    
    // Get the controls that contain the updated values. In this
    // example, the updated values are contained in the TextBox 
    // controls declared in the EditItemTemplates of the TemplateField
 
    // column fields in the GridView control.
    TextBox lastName = (TextBox)row.FindControl("LastNameTextBox");
    TextBox firstName = (TextBox)row.FindControl("FirstNameTextBox");
    
    // Add the updated values to the NewValues dictionary. Use the
    // parameter names declared in the parameterized update query 
    // string for the key names.
    e.NewValues["au_lname"] = lastName.Text;
    e.NewValues["au_fname"] = firstName.Text;    
          
  }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRowCollection Indexer Example</h3>

      <!-- 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="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        autogenerateeditbutton="true"
        datakeynames="au_id"
        cellpadding="10"
        onrowupdating="AuthorsGridView_RowUpdating"      
        runat="server">
                
        <columns>
        
          <asp:boundfield datafield="au_id"
            headertext="Author ID"
            readonly="true"/>
            
          <asp:templatefield headertext="Last Name"
            itemstyle-verticalalign="Top">
            
            <itemtemplate>
              <%#Eval("au_lname")%>
            </itemtemplate>
            
            <edititemtemplate>
              <asp:textbox id="LastNameTextBox"
                text='<%#Eval("au_lname")%>'
                width="90"
                runat="server"/>
              <br/>
              <asp:requiredfieldvalidator id="LastNameRequiredValidator"
                controltovalidate="LastNameTextBox"
                display="Dynamic"
                text="Please enter a last name." 
                runat="server" />                                  
    
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:templatefield headertext="First Name"
            itemstyle-verticalalign="Top">
            
            <itemtemplate>
              <%#Eval("au_fname")%>
            </itemtemplate>
            
            <edititemtemplate>
              <asp:textbox id="FirstNameTextBox"
                text='<%#Eval("au_fname")%>'
                width="90"
                runat="server"/>
              <br/>
              <asp:requiredfieldvalidator id="FirstNameRequiredValidator"
                controltovalidate="FirstNameTextBox"
                display="Dynamic"
                text="Please enter a first name."
                runat="server" />                      
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:checkboxfield datafield="contract" 
            headertext="Contract"
            readonly="true"/>
            
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM
 [authors]"             
        updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname
 WHERE (authors.au_id = @au_id)" 
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

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



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS