Link to home
Start Free TrialLog in
Avatar of dwezil
dwezilFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Can I change the header text in my gridview?

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

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Did you try: this.GridView1.Columns[5].HeaderText = "whatever";
try this...

GridView1.Columns[0].HeaderText = "test";
GridView1.Columns[1].HeaderText = "test1";
Avatar of dwezil

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dwezil

ASKER

Thanks mate