Solved

Can I change the header text in my gridview?

Posted on 2008-10-01
6
1,852 Views
Last Modified: 2013-12-17
This piece of code changes all my column headers to "test" but I need a way to change each column separately. Is there a way  to adapt this code to make different headers for each column? I have five columns. Thanks
foreach (DataControlFieldCell cell in GridView1.HeaderRow.Cells)
            cell.Text = "test";

Open in new window

0
Comment
Question by:dwezil
6 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22613114
Did you try: this.GridView1.Columns[5].HeaderText = "whatever";
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22613118
0
 
LVL 4

Expert Comment

by:sijishJohn
ID: 22613125
try this...

GridView1.Columns[0].HeaderText = "test";
GridView1.Columns[1].HeaderText = "test1";
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:dwezil
ID: 22613140
Yea I've tried that too, get this error--

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
0
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
ID: 22613227
GridView1.HeaderRow.Cells[0].Text = "Text";
0
 

Author Closing Comment

by:dwezil
ID: 31501913
Thanks mate
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question