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

Dim instance As BoundField Dim value As String value = instance.DataField instance.DataField = value
/** @property */ public String get_DataField () /** @property */ public void set_DataField (String value)
BoundField にバインドするデータ フィールドの名前。既定値は空の文字列 ("") です。このプロパティが設定されていないことを示します。

BoundField オブジェクトにバインドするデータ フィールドの名前を指定するには、DataField プロパティを使用します。指定したフィールドの値は、BoundField オブジェクトにテキストとして表示されます。表示するテキストをオプションで書式変換するには、DataFormatString プロパティを設定します。
![]() |
---|
フィールド値が null の場合、既定では空の文字列 ("") が値として表示されます。別のキャプションを指定するには、NullDisplayText プロパティを設定します。 |

DataField プロパティを使用して、GridView コントロールの BoundField フィールド列に表示するフィールドを指定するコード例を次に示します。
<%@ 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>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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