Solved

Can I change the header text in my gridview?

Posted on 2008-10-01
6
1,851 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

861 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