Solved

Can I change the header text in my gridview?

Posted on 2008-10-01
6
1,848 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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