System.Web.UI.WebControls Namespace BoundField Class
.NET Framework version 2.0
Sets or retrieves the name of a field in the data source to bind to a BoundField.
Inline |
<asp:boundfield datafield = strFieldName ... > |
Script |
BoundField.DataField = strFieldName |
strFieldName |
String specifying the name of a field in the data source to bind to a BoundField. |
The property is read/write with no default value.
Use the DataField property to specify the name of a field from the data source to bind to the BoundField control.
The value of the specified field is displayed in the BoundField as a string, regardless of the data type of the field. To specify a custom display format for the field value, set the DataFormatString property.
The following example demonstrates how to set the DataField property at design time, to specify the names of the fields in the data source to bind to the columns of a GridView.
<asp:gridview id = "myGrid" runat = "server" ...
autogeneratecolumns=false>
<columns>
<asp:boundfield headertext = "Type"
datafield = "ProductType" />
<asp:boundfield headertext = "Brand/Model"
datafield = "ProductName" />
<asp:boundfield headertext = "Description"
datafield = "ProductDescription" />
<asp:boundfield headertext = "Price"
datafield = "UnitPrice"
htmlencode=false
dataformatstring = "{0:c}"
itemstyle-horizontalalign = "right" />
</columns>
</asp:gridview>
Show me
BoundField Members