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

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

DataControlFieldCollection.Item プロパティ

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

コレクション内の指定したインデックスでの DataControlField オブジェクト取得または設定します

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

Dim instance As DataControlFieldCollection
Dim index As Integer
Dim value As DataControlField

value = instance(index)
public DataControlField this [
    int index
] { get; }
public:
property DataControlField^ default [int] {
    DataControlField^ get (int index);
}
/** @property */
public DataControlField get_Item (int index)

パラメータ

index

コレクションから取得する DataControlField の 0 から始まるインデックス番号

プロパティ
コレクション内の指定したインデックス位置にある DataControlField

解説解説

このインデクサ使用して配列表記指定したインデックス位置にある DataControlFieldCollection コレクションから DataControlField オブジェクト取得します

使用例使用例

Item インデクサ使用してユーザーコントロール内のボタンクリックしたときに GridView コントロールフィールドアクセスする方法次のコード例示します

<%@ Page language="VB" %>

<script runat="server">

  Sub AuthorsGridView_RowCommand(ByVal sender
 As Object, ByVal e As
 GridViewCommandEventArgs)
  
    ' If multiple ButtonField columns are used, use the
    ' CommandName property to determine which button was clicked.
    Select Case e.CommandName
    
      Case "Edit"
        AuthorsGridView.Columns(0).Visible = False
        AuthorsGridView.Columns(1).Visible = True
      Case "Update"
        AuthorsGridView.Columns(0).Visible = True
        AuthorsGridView.Columns(1).Visible = False
      Case Else
        ' Do nothing.
   
    End Select
    
  End Sub
  
  Sub AuthorsGridView_RowUpdating(ByVal sender
 As Object, ByVal e As
 GridViewUpdateEventArgs)
    
    ' Retrieve the row being edited.    
    Dim index As Integer
 = AuthorsGridView.EditIndex
    Dim row As GridViewRow = AuthorsGridView.Rows(index)
    
    ' Retrieve the new value for the author's first name from the row.
 
    ' In this example, the author's first name is in the second cell
 
    ' of the row (index 1). To get the value, first retrieve the TextBox
    ' that contains the value.
    Dim firstNameTextBox As TextBox = CType(row.Cells(1).FindControl("FirstNameTextBox"),
 TextBox)
    
    ' Make sure the control was found. 
    Dim firstName As String
 = ""
    If Not firstNameTextBox Is
 Nothing Then

      firstName = firstNameTextBox.Text
      
    End If
    
    ' Retrieve the new value for the author's last name from the row.
 
    ' In this example, the author's last name is in the third cell 
    ' of the row (index 2).
    Dim lastNameTextBox As TextBox = CType(row.Cells(2).FindControl("LastNameTextBox"),
 TextBox)
    
    Dim lastName As String
 = ""
    If Not lastNameTextBox Is
 Nothing Then
    
      lastName = lastNameTextBox.Text
      
    End If
    
    ' Because custom TemplateField field columns are used, parameters
 
    ' are not automatically created and passed to the data source control.
    ' Create Parameter objects to represent the fields to update and
 
    ' add the Parameter objects to the UpdateParameters collection.
    Dim lastNameParameter As New
 Parameter("au_lname", TypeCode.String, lastName)
    Dim firstNameParameter As New
 Parameter("au_fname", TypeCode.String, firstName)
    
    ' Clear the UpdateParameters collection before adding the 
    ' Parameter objects. Otherwise, there will be duplicate
    ' parameters.
    AuthorsSqlDataSource.UpdateParameters.Clear()
    AuthorsSqlDataSource.UpdateParameters.Add(lastNameParameter)
    AuthorsSqlDataSource.UpdateParameters.Add(firstNameParameter)
    
  End Sub
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>ButtonFieldBase CausesValidation Example</h3>
                       
      <!-- Populate the Columns collection declaratively. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource"
        cellpadding="5"  
        autogeneratecolumns="false"
        datakeynames="au_id" 
        onrowcommand="AuthorsGridView_RowCommand"
        onrowupdating="AuthorsGridView_RowUpdating"
  
        runat="server">
                
        <columns>
              
          <asp:buttonfield commandname="Edit"
            causesvalidation="false" 
            text="Edit" 
            headertext="Edit Author">
          </asp:buttonfield>
          
          <asp:buttonfield commandname="Update"
 
            visible="false" 
            causesvalidation="true" 
            text="Update"
            validationgroup="NameGroup" 
            headertext="Update Author">
          </asp:buttonfield>
          
          <asp:templatefield headertext="Last Name">
          
            <itemtemplate>
            
              <%#Eval("au_lname") %>
              
            </itemtemplate>
            
            <edititemtemplate>
            
              <asp:textbox id="LastNameTextBox"
                text='<%#Eval("au_lname") %>'
                width="175" 
                runat="server"/>
                
              <br/>  
                
              <asp:requiredfieldvalidator id="LastNameRequiredValidator"
                controltovalidate="LastNameTextBox"
                errormessage="Please enter a last name."
                validationgroup="NameGroup" 
                runat="server"/> 
              
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:templatefield headertext="First Name">
          
            <itemtemplate>
            
              <%#Eval("au_fname") %>
              
            </itemtemplate>
            
            <edititemtemplate>
            
              <asp:textbox id="FirstNameTextBox"
                text='<%#Eval("au_fname") %>'
                width="175" 
                runat="server"/>
                
              <br/>  
                
              <asp:requiredfieldvalidator id="FirstNameRequiredValidator"
                controltovalidate="FirstNameTextBox"
                errormessage="Please enter a first name."
                validationgroup="NameGroup" 
                runat="server"/>
              </asp:requiredfieldvalidator>
              
            </edititemtemplate>
            
          </asp:templatefield>
               
        </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]
 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_RowCommand(Object sender, GridViewCommandEventArgs
 e)
  {
  
    // If multiple ButtonField columns are used, use the
    // CommandName property to determine which button was clicked.
    switch(e.CommandName)
    {
    
      case "Edit":
        AuthorsGridView.Columns[0].Visible = false;
        AuthorsGridView.Columns[1].Visible = true;
        break;
      case "Update":
        AuthorsGridView.Columns[0].Visible = true;
        AuthorsGridView.Columns[1].Visible = false;
        break;
      default:
        // Do nothing.
        break;
    }
    
  }
  
  void AuthorsGridView_RowUpdating (Object sender, GridViewUpdateEventArgs
 e)
  {
    
    // Retrieve the row being edited.    
    int index = AuthorsGridView.EditIndex;
    GridViewRow row = AuthorsGridView.Rows[index];
    
    // Retrieve the new value for the author's first name from the row.
 
    // In this example, the author's first name is in the second cell
 
    // of the row (index 1). To get the value, first retrieve the TextBox
    // that contains the value.
    TextBox firstNameTextBox = (TextBox)row.Cells[1].FindControl("FirstNameTextBox");
    
    // Make sure the control was found. 
    String firstName = "";    
    if(firstNameTextBox != null)
    {
      firstName = firstNameTextBox.Text;
    }
    
    // Retrieve the new value for the author's last name from the row.
 
    // In this example, the author's last name is in the third cell
 
    // of the row (index 2).
    TextBox lastNameTextBox = (TextBox)row.Cells[2].FindControl("LastNameTextBox");
    
    String lastName = "";
    if(lastNameTextBox != null)
    {
      lastName = lastNameTextBox.Text;
    }
    
    // Because custom TemplateField field columns are used, parameters
 
    // are not automatically created and passed to the data source control.
    // Create Parameter objects to represent the fields to update and
 
    // add the Parameter objects to the UpdateParameters collection.
    Parameter lastNameParameter = new Parameter("au_lname",
 TypeCode.String, lastName);   
    Parameter firstNameParameter = new Parameter("au_fname",
 TypeCode.String, firstName);
    
    // Clear the UpdateParameters collection before adding the 
    // Parameter objects. Otherwise, there will be duplicate
    // parameters.
    AuthorsSqlDataSource.UpdateParameters.Clear();
    AuthorsSqlDataSource.UpdateParameters.Add(lastNameParameter);
    AuthorsSqlDataSource.UpdateParameters.Add(firstNameParameter);
    
  }
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>ButtonFieldBase CausesValidation Example</h3>
                       
      <!-- Populate the Columns collection declaratively. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource"
        cellpadding="5"  
        autogeneratecolumns="false"
        datakeynames="au_id" 
        onrowcommand="AuthorsGridView_RowCommand"
        onrowupdating="AuthorsGridView_RowUpdating"  
        runat="server">
                
        <columns>
              
          <asp:buttonfield commandname="Edit"
            causesvalidation="false" 
            text="Edit" 
            headertext="Edit Author">
          </asp:buttonfield>
          
          <asp:buttonfield commandname="Update" 
            visible="false" 
            causesvalidation="true" 
            text="Update"
            validationgroup="NameGroup" 
            headertext="Update Author">
          </asp:buttonfield>
          
          <asp:templatefield headertext="Last Name">
          
            <itemtemplate>
            
              <%#Eval("au_lname") %>
              
            </itemtemplate>
            
            <edititemtemplate>
            
              <asp:textbox id="LastNameTextBox"
                text='<%#Eval("au_lname") %>'
                width="175" 
                runat="server"/>
                
              <br/>  
                
              <asp:requiredfieldvalidator id="LastNameRequiredValidator"
                controltovalidate="LastNameTextBox"
                errormessage="Please enter a last name."
                validationgroup="NameGroup" 
                runat="server"/> 
              
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:templatefield headertext="First Name">
          
            <itemtemplate>
            
              <%#Eval("au_fname") %>
              
            </itemtemplate>
            
            <edititemtemplate>
            
              <asp:textbox id="FirstNameTextBox"
                text='<%#Eval("au_fname") %>'
                width="175" 
                runat="server"/>
                
              <br/>  
                
              <asp:requiredfieldvalidator id="FirstNameRequiredValidator"
                controltovalidate="FirstNameTextBox"
                errormessage="Please enter a first name."
                validationgroup="NameGroup" 
                runat="server"/>
              </asp:requiredfieldvalidator>
              
            </edititemtemplate>
            
          </asp:templatefield>
               
        </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] 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>

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


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS