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

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

BoundField.DataFormatString プロパティ

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

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

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

Public Overridable Property
 DataFormatString As String
Dim instance As BoundField
Dim value As String

value = instance.DataFormatString

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

/** @property */
public void set_DataFormatString (String value)
public function get DataFormatString
 () : String

public function set DataFormatString
 (value : String)

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

解説解説

BoundField オブジェクトに表示する値のカスタムの表示形式を指定するには、DataFormatString プロパティを使用します。DataFormatString プロパティを設定しない場合、フィールド値が特に書式変換されずに表示されます。

メモメモ

HtmlEncode プロパティが true の場合、フィールド値が文字列形式に HTML エンコードされてから書式指定文字列が適用されます。日付など、一部のオブジェクトでは、書式指定文字列を使用してオブジェクトを表示する形式を制御することが必要になる場合があります。そのような場合は、HtmlEncode プロパティを false に設定する必要があります。

既定では、BoundField オブジェクトを格納するデータ バインド コントロールが読み取り専用モードの場合だけ、書式指定文字列がフィールド値に適用されます。編集モードで書式指定文字列をフィールド値に適用するには、ApplyFormatInEditMode プロパティを true に設定します。

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

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

メモメモ

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

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

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

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

使用例使用例

DataFormatString プロパティを使用して、フィールドの値のカスタム表示形式を指定するコード例を次に示します。フィールド内の数値は、書式変換され、小数点以下 4 桁が表示されます。

<%@ Page language="VB" %>

<html>
  <body>
    <form runat="server">
        
      <h3>BoundField DataField Example</h3>

      <asp:gridview id="DiscountsGridView" 
        datasourceid="DiscountsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">
                
        <columns>            
          <asp:boundfield datafield="discounttype"
            headertext="Discount Type"/>      
              
          <asp:boundfield datafield="discount"
            dataformatstring="{0:F4}%"
            itemstyle-horizontalalign="Right"  
            headertext="Discount"/>           
     
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects
 -->
      <!-- to the Pubs sample database.                   
     -->
      <asp:sqldatasource id="DiscountsSqlDataSource"
  
        selectcommand="SELECT [discounttype], [stor_id], [lowqty],
 [highqty], [discount] FROM [discounts]"
        connectionstring="<%$ ConnectionStrings:PubsConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

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

<html>
  <body>
    <form runat="server">
        
      <h3>BoundField DataField Example</h3>

      <asp:gridview id="DiscountsGridView" 
        datasourceid="DiscountsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">
                
        <columns>
          <asp:boundfield datafield="discounttype"
            headertext="Discount Type"/>                    
          <asp:boundfield datafield="discount"
            dataformatstring="{0:F4}%"
            itemstyle-horizontalalign="Right"  
            headertext="Discount"/>                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="DiscountsSqlDataSource"  
        selectcommand="SELECT [discounttype], [stor_id], [lowqty], [highqty],
 [discount] FROM [discounts]"
        connectionstring="<%$ ConnectionStrings:PubsConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
BoundField クラス
BoundField メンバ
System.Web.UI.WebControls 名前空間
BoundField.DataField プロパティ
BoundField.ApplyFormatInEditMode プロパティ
その他の技術情報
書式設定の概要


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

英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「BoundField.DataFormatString プロパティ」の関連用語

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

   

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



BoundField.DataFormatString プロパティのページの著作権

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

©2026 GRAS Group, Inc.RSS