BoundField クラス
アセンブリ: System.Web (system.web.dll 内)


BoundField クラスはフィールドの値をテキストとして表示するために、データ バインド コントロール (GridView、DetailsView など) で使用されます。BoundField オブジェクトは、それが使用されているデータ バインド コントロールによって表示が異なります。たとえば、BoundField オブジェクトは、GridView コントロールでは列として表示され、DetailsView コントロールでは行として表示されます。
BoundField オブジェクトに表示するフィールドを指定するには、DataField プロパティをフィールドの名前に設定します。フィールド値を表示する前に HTML エンコードするには、HtmlEncode プロパティを true に設定します。カスタムの書式指定文字列をフィールド値に適用するには、DataFormatString プロパティを設定します。HtmlEncode プロパティが true の場合、エンコードされた、フィールドの文字列値がカスタム書式指定文字列で使用されます。既定では、データ バインド コントロールが読み取り専用モードの場合だけ、書式指定文字列がフィールド値に適用されます。データ バインド コントロールが編集モードの場合に書式指定文字列を表示値に適用するには、ApplyFormatInEditMode プロパティを true に設定します。フィールド値が null の場合にカスタムのキャプションを表示するには、NullDisplayText プロパティを設定します。BoundField オブジェクトは、ConvertEmptyStringToNull プロパティを true に設定することにより、空の文字列 ("") フィールド値を null 値に自動的に変換します。
データ バインド コントロール内の BoundField オブジェクトを非表示にするには、Visible プロパティを false に設定します。編集モードでフィールドの値が変更されるのを防ぐには、ReadOnly プロパティを true に設定します。レコードの挿入をサポートするデータ バインド コントロール (DetailsView コントロールなど) で BoundField オブジェクトを非表示にするには、InsertVisible プロパティを false に設定します。挿入モードで自動生成されたキー フィールドを非表示にする場合は、通常この方法を使用します。
BoundField オブジェクトのヘッダー セクションとフッター セクションをカスタマイズできます。ヘッダー セクションにキャプションを表示するには、HeaderText プロパティを設定します。フッター セクションにキャプションを表示するには、FooterText プロパティを設定します。ヘッダー セクションにテキストを表示する代わりに、HeaderImageUrl プロパティを設定してイメージを表示できます。ShowHeader プロパティを false に設定することにより、BoundField オブジェクトでヘッダー セクションを非表示にできます。
![]() |
---|
一部のデータ バインド コントロール (GridView コントロールなど) では、コントロールのヘッダー セクション全体を表示または非表示にできます。これらのデータ バインド コントロールは、個別にバインドされたフィールドの ShowHeader プロパティをサポートしません。データ バインド コントロールのヘッダー セクション (存在する場合) 全体を表示または非表示にするには、コントロールの ShowHeader プロパティを使用します。 |
フィールドの各部分にスタイル プロパティを設定することにより、BoundField オブジェクトの外観 (フォントの色や背景色など) をカスタマイズすることもできます。さまざまなスタイル プロパティの一覧を次の表に示します。

BoundField オブジェクトを使用して、GridView コントロールにフィールドの値を表示するコード例を次に示します。
<%@ Page language="VB" %> <html> <body> <form runat="server"> <h3>BoundField Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" autogenerateeditbutton="true" allowpaging="true" datakeynames="CustomerID" runat="server"> <columns> <asp:boundfield datafield="CustomerID" readonly="true" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" convertemptystringtonull="true" headertext="Customer Name"/> <asp:boundfield datafield="Address" convertemptystringtonull="true" headertext="Address"/> <asp:boundfield datafield="City" convertemptystringtonull="true" headertext="City"/> <asp:boundfield datafield="PostalCode" convertemptystringtonull="true" headertext="ZIP Code"/> <asp:boundfield datafield="Country" convertemptystringtonull="true" headertext="Country"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" updatecommand="Update Customers Set CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <html> <body> <form runat="server"> <h3>BoundField Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" autogenerateeditbutton="true" allowpaging="true" datakeynames="CustomerID" runat="server"> <columns> <asp:boundfield datafield="CustomerID" readonly="true" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" convertemptystringtonull="true" headertext="Customer Name"/> <asp:boundfield datafield="Address" convertemptystringtonull="true" headertext="Address"/> <asp:boundfield datafield="City" convertemptystringtonull="true" headertext="City"/> <asp:boundfield datafield="PostalCode" convertemptystringtonull="true" headertext="ZIP Code"/> <asp:boundfield datafield="Country" convertemptystringtonull="true" headertext="Country"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" updatecommand="Update Customers Set CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>


System.Web.UI.WebControls.DataControlField
System.Web.UI.WebControls.BoundField
System.Web.UI.WebControls.AutoGeneratedField
System.Web.UI.WebControls.CheckBoxField


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 クラスを検索する場合は、下記のリンクをクリックしてください。

- BoundField クラスのページへのリンク