Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can I change the header text in my gridview?

Posted on 2008-10-01
6
Medium Priority
?
1,865 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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 2000 total points
ID: 22613227
GridView1.HeaderRow.Cells[0].Text = "Text";
0
 

Author Closing Comment

by:dwezil
ID: 31501913
Thanks mate
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

824 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