asp.net.ph

Skip Navigation Links

Adding Bound Columns to a DataGrid Control

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


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

For additional information, see BoundColumn in the class library.

See Also

Adding Button Columns to a DataGrid Control   Adding Hyperlink Columns to a DataGrid Control   Adding Template Columns to a DataGrid 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