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

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

ButtonField.DataTextFormatString プロパティ

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

フィールド値の表形式指定する文字列取得または設定します

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

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

value = instance.DataTextFormatString

instance.DataTextFormatString = value
public virtual string DataTextFormatString
 { get; set; }
public:
virtual property String^ DataTextFormatString {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_DataTextFormatString ()

/** @property */
public void set_DataTextFormatString (String
 value)
public function get DataTextFormatString
 () : String

public function set DataTextFormatString
 (value : String)

プロパティ
フィールド値の表形式指定する書式指定文字列既定値空の文字列です ("")。この値は、フィールド値に適用される特定の書式設定されていないことを示します

解説解説

DataTextFormatString プロパティ使用すると、ButtonField オブジェクト表示される値の表書式指定できますDataTextFormatString プロパティ設定しないと、フィールドの値は特定の書式使用せず表示されます。

メモメモ

DataTextField プロパティ設定した場合限り書式指定文字列適用されます。

書式指定文字列には、任意のリテラル文字列使用でき、通常フィールドの値のプレースホルダを含めます。たとえば、書式指定文字列 "Item Value: {0}"ButtonField オブジェクト表示されると、{0} プレースホルダはそのフィールドの値に置き換えられます。書式指定文字列残り部分は、リテラル テキストとして表示されます。

プレースホルダは、{ A : Bxx } の形式で、中かっこ囲まれた、コロン区切り2 つ部分から構成されます。コロンの前の値 (一般的な例での A) には、フィールド値のインデックスを 0 から始まるパラメータ リスト形式指定します

メモメモ

この A パラメータは、書式指定構文一部です。各セルフィールド値を 1 つしか格納できないので、この値は必ず 0 に設定します

コロンおよびコロンの後の値は省略可能です。コロンの後の文字 (一般的な例での B) には、値を表示する際に使用する書式指定します。共通の書式次の表に示します

書式指定文字の後の値 (一般的な例での xx) は、表示する有効桁数または小数点指定します。たとえば、書式指定文字列 "{0:F2}"使用すると、2 固定小数点数表示されます。

書式指定文字列詳細については、「書式設定概要」を参照してください

このプロパティの値はビューステート格納されます。

使用例使用例

DataTextFormatString プロパティ使用してフィールド値のカスタム表示書式指定する方法次のコード例示します

<%@ 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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS