System.Web.UI.WebControls Namespace BoundColumn Class
Sets or retrieves the field from the data source to bind to the column.
Inline |
<asp:boundcolumn datafield = strFieldName ... > |
Script |
BoundColumn.DataField = strFieldName |
strFieldName |
String specifying the name of a field to bind to the column. |
The property is read/write with no default value.
Use the DataField property to specify the field name from a data source to bind to the column.
You can specify a custom display format for the field values by setting 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 DataGrid.
<asp:datagrid id = "myGrid" runat = "server" ...
autogeneratecolumns=false>
<columns>
<asp:boundcolumn headertext = "Type"
datafield = "ProductType" />
<asp:boundcolumn headertext = "Brand/Model"
datafield = "ProductName" />
<asp:boundcolumn headertext = "Description"
datafield = "ProductDescription" />
<asp:boundcolumn headertext = "Price"
datafield = "UnitPrice"
dataformatstring = "{0:c}"
itemstyle-horizontalalign = "right" />
</columns>
</asp:datagrid>
Show me
BoundColumn Members Adding Bound Columns to a DataGrid Control