Click here to Skip to main content
15,937,429 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

when i host my site and access a particular page it shows an error

"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"



please provide your idea



it shows the error like this.........






Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +64
System.ThrowHelper.ThrowArgumentOutOfRangeException() +15
System.Collections.Generic.List`1.get_Item(Int32 index) +7495292
MedVisit_Web.GMapPatientInfo..ctor(VisitDetails visit) +610
MedVisit_Web.AssignMap.SetDataSources() +616
MedVisit_Web.AssignMap.Page_Load(Object sender, EventArgs e) +188
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627




--------------------------------------------------------------------------------


regards,
Shefeek
Posted
Updated 6-Jan-17 14:44pm
v3

Quote:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
The message tells you all.
Your code try to access an element that do not exist in an array or list.

Try to run your page on debugger, when error occurs, pay attention to the value of index and to the size of the array/list.
 
Share this answer
 
hi please use below method when you used datatable
DataTable dt = new DataTable();
        if (dt.Rows.Count > 0)
        { 
        //Your code
        }
 
Share this answer
 
Comments
Dave Kreskowiak 6-Jan-17 21:09pm    
Check the date on the post before you answer.

This question was asked and answered almost SIX YEARS AGO.
[no name] 7-Jan-17 4:49am    
so what
[no name] 7-Jan-17 7:50am    
So the question was asked and ANSWERED SIX YEARS ago. There is no reason for you to come along and resurrect ancient already answered questions just so you can get some rep points that don't mean anything.
Kaviya R 17-Jun-21 2:07am    
Error in the page
Dave Kreskowiak 17-Jun-21 10:34am    
...and that's supposed to mean what in this context?

Nothing. It means nothing at all.
The is something wrong in your Page Load event , or the initial values set to the controls in the page are not correct.

Please put down you code fragment, we may help you better.
 
Share this answer
 
Comments
shefeekcm 11-Aug-11 4:43am    
its working in locally without any problem
How about debugging the page? The error message is telling exactly what is the problem with the code.

Update: See this in the stack:

VB
System.Collections.Generic.List`1.get_Item(Int32 index) +7495292
MedVisit_Web.GMapPatientInfo..ctor(VisitDetails visit) +610



You are trying to access some non-existant item in the list.
 
Share this answer
 
v2
Comments
shefeekcm 11-Aug-11 4:43am    
its working in locally without any problem
dan!sh 11-Aug-11 4:47am    
Updated the reply.
shefeekcm 11-Aug-11 4:57am    
it does not shows any error when i works in my system
shefeekcm 25-Aug-11 7:58am    
you are right....?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900