DataTable and GridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • E11esar
    New Member
    • Nov 2008
    • 132

    DataTable and GridView

    Hi there.

    I have a DataTable with around 20 columns in it and a GridView that is bound to the DataTable.

    Is it possible to specify which columns the GridView has to bind to please?

    While I would like to use this one DataTable (as it is used for other parts of a web page) can I be so selective in the columns used?

    Thank you.

    M :o)
  • E11esar
    New Member
    • Nov 2008
    • 132

    #2
    Solution

    Set GridView's AutoGenerateCol umns property to false and create bound fields for the grid view as shown below:

    Code:
    <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" >
    
    <Columns>
    
    <asp:BoundField DataField="CustomerID" HeaderText="Customer ID"/>
    
    <asp:BoundField DataField="CompanyName" HeaderText="Company Name"/>
    
    <asp:BoundField DataField="ContactName" HeaderText="Contact Name" />
    
    <asp:BoundField DataField="ContactTitle" HeaderText="Contact Title" />
    
    </Columns>
    
    </asp:GridView>
    Thank you.

    M :o)

    Comment

    Working...