Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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