Solved

Gridview -  Index was out of range.

Posted on 2009-05-11
4
361 Views
Last Modified: 2012-05-06
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
Comment
Question by:Mr_Shaw
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Chandan_Gowda earned 250 total points
ID: 24352634
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
 
LVL 9

Assisted Solution

by:Deathrace
Deathrace earned 250 total points
ID: 24352650
hey,
try chaning the index value to 3 , if you have 4 columns in your Grid, that might be the cause.
0
 

Author Closing Comment

by:Mr_Shaw
ID: 31580066
thanks
0
 

Author Comment

by:Mr_Shaw
ID: 24352762
the code which worked was

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

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading the Web.Config using IIS 7.5? 4 49
C# bracket error 3 36
How to make a Gridview column hidden (visibility false) in the HTML code? 2 19
abstract class C# 1 31
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question