asp.net.ph

BoundField.DataField Property

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.

Syntax


Inline <asp:boundfield datafield = strFieldName ... >
Script BoundField.DataField = strFieldName

Property Value


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.

Remarks

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.

Example

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 

See Also

BoundField Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph