Using the BoundField for explicitly specifying Columns : BoundField « Data Binding « ASP.Net






Using the BoundField for explicitly specifying Columns

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Using the BoundField for explicitly specifying Columns</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="productsSource" runat="server"
            ProviderName="System.Data.SqlClient" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorks %>"
            SelectCommand="Select ProductID, Name, ProductNumber, DaysToManufacture from Production.Product">            
        </asp:SqlDataSource>
        <asp:GridView runat="server" ID="gridProducts" DataSourceID="productsSource"
            AutoGenerateColumns="false">        
            <Columns>
                <asp:BoundField DataField="ProductID" HeaderText="ID" />
                <asp:BoundField DataField="Name" HeaderText="Name" />
                <asp:BoundField DataField="ProductNumber" HeaderText="Number" />
                <asp:BoundField DataField="DaysToManufacture" HeaderText="Days To Manufacture" />                
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>

 








Related examples in the same category

1.BoundField as GridView columns
2.Adding multicolumn sorting to the GridView (C#)
3.Adding multicolumn sorting to the GridView (VB)
4.BoundField with ItemStyle