Link to home
Create AccountLog in
AZZA-KHAMEESFlag for Bahrain

asked on

error in changing column name

Hi expert, i am using visual studio .net 2005, i have a datagrid that are filled with an array of struct, i want to change the header of each column in the grid so i used
GridView1.Columns[0].HeaderText = "new";
but i got an error "" Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index""
then i use <Columns><asp:BoundField DataField="_column1" HeaderText="new" /></column>
it worked but it duplicate the column like this:

new     _column1
1              1

so i get the same column two time with diffrent header name the new and the old header
can you help me to solve this problem?? did i missed some tags??
Avatar of Dustin Hopkins
Dustin Hopkins
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Where are you putting the GridView1.Columns[0].HeaderText = "new"; statement? is it in page_load? if the names aren't going to change then there should be no problem using your second method.
Do you have datasource for the gridview, or databinding? If yes you probably can't change the name of the column...