BoundField.DataFormatString プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As BoundField Dim value As String value = instance.DataFormatString instance.DataFormatString = 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) は値を表示する書式を指定します。共通の書式を次の表に示します。
C | |
D | |
E | |
F | |
G | |
N | |
X |
書式指定文字の後の値 (一般的な例での 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からBoundField.DataFormatString プロパティを検索する場合は、下記のリンクをクリックしてください。

- BoundField.DataFormatString プロパティのページへのリンク