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

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

ButtonField.DataTextField プロパティ

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

ButtonField オブジェクト表示する Button コントロールText プロパティバインドされている値のデータ フィールド名を取得または設定します

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

Public Overridable Property
 DataTextField As String
Dim instance As ButtonField
Dim value As String

value = instance.DataTextField

instance.DataTextField = value
public virtual string DataTextField { get;
 set; }
/** @property */
public String get_DataTextField ()

/** @property */
public void set_DataTextField (String value)
public function get DataTextField
 () : String

public function set DataTextField
 (value : String)

プロパティ
ButtonFieldバインドするフィールドの名前。既定値空の文字列 ("") です。この値は DataTextField プロパティ設定されていないことを示します

解説解説
使用例使用例

次のコード例では、DataTextField プロパティ使用して、GridView コントロールButtonField 列に表示するフィールド指定する方法示します

<%@ Page language="VB" %>

<script runat="server">

  Sub AuthorsGridView_RowCommand(ByVal sender
 As Object, ByVal e As
 GridViewCommandEventArgs)
  
    ' If multiple ButtonField column fields are used, use the
    ' CommandName property to determine which button was clicked.
    If e.CommandName = "Select"
 Then
    
      ' Convert the row index stored in the CommandArgument
      ' property to an Integer.
      Dim index As Integer
 = Convert.ToInt32(e.CommandArgument)
    
      ' Get the last name of the selected author from the appropriate
      ' cell in the GridView control.
      Dim selectedRow As GridViewRow = AuthorsGridView.Rows(index)
      Dim lastNameCell As TableCell = selectedRow.Cells(1)
      Dim lastName As String
 = lastNameCell.Text
    
      ' Display the selected author.
      Message.Text = "You selected " & lastName
 & "."
      
    End If
    
  End Sub
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>ButtonField DataTextField Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                    
      <!-- Set the DataTextField property
 of the ButtonField -->
      <!-- declaratively. Set the DataTextFormatString    
   -->
      <!-- property to apply special formatting
 to the text. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="AuthorsGridView_RowCommand"
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Link" 
            commandname="Select"
            headertext="Select Author"
            datatextfield="au_lname"
            datatextformatstring="[{0}]"    
            text="Select"/>
          <asp:boundfield datafield="au_fname"
 
            headertext="First Name"/>
                
        </columns>
                
      </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] FROM [authors]"
        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 column fields are used, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="Select")
    {
    
      // Convert the row index stored in the CommandArgument
      // property to an Integer.
      int index = Convert.ToInt32(e.CommandArgument);    
    
      // Get the last name of the selected author from the appropriate
      // cell in the GridView control.
      GridViewRow selectedRow = AuthorsGridView.Rows[index];
      TableCell lastNameCell = selectedRow.Cells[1];
      string lastName = lastNameCell.Text;  
    
      // Display the selected author.
      Message.Text = "You selected " + lastName + ".";
      
    }
    
  }
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>ButtonField DataTextField Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                    
      <!-- Set the DataTextField property of the ButtonField -->
      <!-- declaratively. Set the DataTextFormatString       -->
      <!-- property to apply special formatting to the text. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="AuthorsGridView_RowCommand" 
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Link" 
            commandname="Select"
            headertext="Select Author"
            datatextfield="au_lname"
            datatextformatstring="[{0}]"    
            text="Select"/>
          <asp:boundfield datafield="au_fname" 
            headertext="First Name"/>
                
        </columns>
                
      </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] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

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


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

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

辞書ショートカット

すべての辞書の索引

「ButtonField.DataTextField プロパティ」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS