473,396 Members | 1,816 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,396 software developers and data experts.

Configuring Columns of a GridView

Hi,

I want to Chang header file of Gridview so i use this code :

GridView1.Columns[1].HeaderText = "nummber";

But it doesn't work !! :(

and

I don't know how can i show just 3 Columns of 7 Columns of table in GridView???

Please Help Me .

thank.
May 16 '10 #1
2 1557
@marjani
if u want to show three column in a grid view u just bound those field u want to display in a grid view
so simpleeeeeeee

By the way why u change the header name of an column by code behind , u can do easily by the aspx page.
May 16 '10 #2
Frinavale
9,735 Expert Mod 8TB
Marjani,

If you want to have more control over your GridView and what it displays you should consider configuring it so that it does not auto-generate the columns for you.

You can do this by setting the AutoGenerateColumns property to False.

Once you've done this you have to manually go in set the columns you want to display.

You can do this using the Visual Studio IDE: in Design view of your page, click on the GridView, look at the Properties for the GridView, find the Columns property and click the "..." button to add Columns.

You can do this in Source View of your page (this is the method that I prefer)...find the <asp:GridView> element...make sure it's AutoGenerateColumns property is set to False, and add your columns into the <columns> section within the GridView.

For Example:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="myGrid" runat="server" AutoGenerateCollumns="False">
  2.   <Columns>
  3.       <asp:BoundField DataField="abc" HeaderText="Description for ABC" />
  4.       <asp:BoundField DataField="lmnop" HeaderText="Description for LMNOP" 
  5.       <asp:BoundField DataField="xyz" HeaderText="Description for XYZ" />/>
  6.   </Columns>
  7. </asp:GridView>
Just make sure that the DataField property matches the name of the Data Field that the column is begin bound to or this wont work :)

You can also do this dynamicallyin in your C# code but I'm not going to get into that because this method is complicated.

-Frinny
May 17 '10 #3

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

Similar topics

3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
1
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
0
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.