DataControlFieldCollection.Add メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataControlFieldCollection.Add メソッドの意味・解説 

DataControlFieldCollection.Add メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定した DataControlField オブジェクトコレクション末尾追加します

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

Public Sub Add ( _
    field As DataControlField _
)
Dim instance As DataControlFieldCollection
Dim field As DataControlField

instance.Add(field)
public void Add (
    DataControlField field
)
public:
void Add (
    DataControlField^ field
)
public void Add (
    DataControlField field
)
public function Add (
    field : DataControlField
)

パラメータ

field

コレクション末尾追加する DataControlField。

解説解説
使用例使用例

Add メソッド使用して、CheckBoxField オブジェクトを GridView コントロール動的に追加する方法次のコード例示します

<%@ Page language="VB" %>

<script runat="server">

  Sub Page_Load(sender as Object,
 e As EventArgs)
  
    ' The columns need to be created only the first time
    ' the page is loaded.
    If Not IsPostBack Then

      ' Dynamically create columns to display the desired
      ' fields from the data source. Columns that are 
      ' dynamically added to the GridView control are not persisted
 
      ' across posts and must be recreated each time the page is 
      ' loaded.
  
      ' Create a BoundField object to display an author's last name.
      Dim lastNameBoundField As BoundField
 = New BoundField
      lastNameBoundField.DataField = "au_lname"
      lastNameBoundField.HeaderText = "Last Name"
    
      ' Create a CheckBoxField object to indicate whether the author
      ' is on contract.
      Dim contractCheckBoxField As CheckBoxField
 = New CheckBoxField
      contractCheckBoxField.DataField = "contract"
      contractCheckBoxField.HeaderText = "Contract"
    
      ' Add the columns to the Columns collection of the
      ' GridView control.
      AuthorsGridView.Columns.Add(lastNameBoundField)
      AuthorsGridView.Columns.Add(contractCheckBoxField)

    End If
  
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>CheckBoxField Constructor Example</h3>

      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects
 -->
      <!-- to the Pubs sample database.                   
     -->
      <asp:sqldatasource id="AuthorsSqlDataSource"
  
        selectcommand="SELECT [au_lname], [au_fname], [address],
 [city], [state], [zip], [contract] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated
 security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

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

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    // The columns need to be created only the first time
    // the page is loaded.
    if(!IsPostBack)
    {
  
      // Dynamically create columns to display the desired
      // fields from the data source. Columns that are 
      // dynamically added to the GridView control are not persisted
 
      // across posts and must be recreated each time the page is 
      // loaded.
  
      // Create a BoundField object to display an author's last name.
      BoundField lastNameBoundField = new BoundField();
      lastNameBoundField.DataField = "au_lname";
      lastNameBoundField.HeaderText = "Last Name";
    
      // Create a CheckBoxField object to indicate whether the author
      // is on contract.
      CheckBoxField contractCheckBoxField = new CheckBoxField();
      contractCheckBoxField.DataField = "contract";
      contractCheckBoxField.HeaderText = "Contract";
    
      // Add the columns to the Columns collection of the
      // GridView control.
      AuthorsGridView.Columns.Add(lastNameBoundField);
      AuthorsGridView.Columns.Add(contractCheckBoxField);

    }
  
  }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>CheckBoxField Constructor Example</h3>

      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname], [address], [city], [state],
 [zip], [contract] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

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



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

辞書ショートカット

すべての辞書の索引

DataControlFieldCollection.Add メソッドのお隣キーワード
検索ランキング

   

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



DataControlFieldCollection.Add メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS