Link to home
Start Free TrialLog in
Avatar of Mr_Shaw
Mr_Shaw

asked on

Gridview - Index was out of range.

I have a gridview which I have populated using

Gridview1.DataSource = DataSet1;
Gridview1.databind();

when I run the following code

Gridview.Columns[4].ItemStyle.Width = 100;

I get an error saying Index was out of range.

I just don't understand as column 4 exists.
ASKER CERTIFIED SOLUTION
Avatar of Chandan_Gowda
Chandan_Gowda
Flag of United States of America 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
SOLUTION
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 Mr_Shaw
Mr_Shaw

ASKER

thanks
Avatar of Mr_Shaw

ASKER

the code which worked was

 if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[4].Width = 500;
        }