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 プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS