asp.net.ph

Skip Navigation Links

Adding Bound Fields to a GridView Control

Controls You Can Use on Web Forms   ASP.NET Data Controls   GridView Control


A BoundField in a GridView control enables authors to specify which of the fields from the data source will display and in what order, as well as to customize information such as the column’s header text and data display format.

To add bound columns

  1. Set the GridView control’s AutoGenerateColumns property to false.
    <asp:GridView id="myGrid" runat="server"
       autogeneratecolumns=false
       ...
    >
  2. Within the GridView declaration, declare a <Columns> element.
  3. Within the Columns element, define each of the <asp:BoundField> controls you intend to display, specifying at the very least the required DataField property for each column.
  4. Optionally set the BoundField control’s other properties, such as the HeaderText and DataFormatString. For syntax, see GridView Control Syntax.
    <columns>
    
       <asp:boundfield headertext="Type"
          datafield="ProductType" />
    
       ...
    
       <asp:boundfield headertext="Price"
          datafield="UnitPrice"
          htmlencode=false
          dataformatstring="{0:c}" 
          itemstyle-horizontalalign="right" />
    
    </columns>
GridView BoundField Example
Run Sample | View Source

For additional information, see BoundField in the class library.

See Also

Adding Button Fields to a GridView Control   Adding Hyperlink Fields to a GridView Control   Adding Template Fields to a GridView Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

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