Solved

Gridview -  Index was out of range.

Posted on 2009-05-11
4
356 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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0
 

Author Comment

by:Mr_Shaw
Comment Utility
the code which worked was

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now