By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

DataTable and GridView

100+
P: 132
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)
Feb 24 '09 #1
Share this Question
Share on Google+
1 Reply


100+
P: 132
Set GridView's AutoGenerateColumns property to false and create bound fields for the grid view as shown below:

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" >
  2.  
  3. <Columns>
  4.  
  5. <asp:BoundField DataField="CustomerID" HeaderText="Customer ID"/>
  6.  
  7. <asp:BoundField DataField="CompanyName" HeaderText="Company Name"/>
  8.  
  9. <asp:BoundField DataField="ContactName" HeaderText="Contact Name" />
  10.  
  11. <asp:BoundField DataField="ContactTitle" HeaderText="Contact Title" />
  12.  
  13. </Columns>
  14.  
  15. </asp:GridView>
  16.  
  17.  
Thank you.

M :o)
Feb 24 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.