Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

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.
0
Mr_Shaw
Asked:
Mr_Shaw
  • 2
2 Solutions
 
Chandan_GowdaCommented:
1) First find how many columns you have in the grid (Gridview.Columns.count)
2)analyze the column index thru immediate window of VS.Net.
0
 
DeathraceCommented:
hey,
try chaning the index value to 3 , if you have 4 columns in your Grid, that might be the cause.
0
 
Mr_ShawAuthor Commented:
thanks
0
 
Mr_ShawAuthor Commented:
the code which worked was

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now