Solved

Can I change the header text in my gridview?

Posted on 2008-10-01
6
1,856 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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