473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataTable and GridView

132 100+
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
1 1700
E11esar
132 100+
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

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

Similar topics

1
by: j.zascinski | last post by:
Hi, i have a "simple" problem with gridview, please help me :) i want to have gridview which is binded to a datatable (or a dataset). i can show the data from the dataset in the gridview and i can...
0
by: witek | last post by:
I am lost. There is a dataTable with data which I want to dispaly in GridView. dataTable is not connected to any database. Just dataTable with data. There is a class wich is used as column...
0
by: Elmo Watson | last post by:
OK - main gridview - gvTV In one column - I have another Gridview - gvTRPTV - function: Public Function AddTRPRow() As DataTable dtHeader = CType(ViewState("Header"), DataTable) If dtHeader...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
1
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint...
2
by: Tim | last post by:
I'm using a GridView with its DataSource property set to a DataTable. During the RowDataBound event, the first row of the DataTable is reported as a DataControlRowType.Header instead of...
3
by: ASPnewb1 | last post by:
I am currently filling a dataTable then adding this table to a dataset, setting the dataset to the Gridview's datasource. If I set the Gridview to generate columns automatically it will fill the...
2
by: DC | last post by:
Hi, I am using a GridView to present data in a DataTable, which I store only in ViewState and when the user hits the "OK" button the rows in the DataTable will be used to execute transactions. ...
0
by: Andy B | last post by:
I have the following gridview. There are 2 other textBoxes and a button on the page as well. When somebody puts text into the 2 textBoxes and presses the add button, it puts the values of those...
2
by: tonymcq | last post by:
I am very new to VB.net / ASP and have spent hours and hours trying to solve what must be a simple problem - hopefully someone can point me in the right direction. I have a gridview bound to an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.