Click here to Skip to main content
14,934,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone,

I've got following error:


HTML
There is no row at position 255. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IndexOutOfRangeException: There is no row at position 255.

Source Error: 


Line 263:                    {
Line 264:
Line 265:                        dt_gridcom.Rows[s][k] = summary;
Line 266:                        if (summary.Length > 25)
Line 267:                   dt_grid.Rows[s][k] = summary.Substring(0, 25) + "...";
 

Source File: d:\Maestro\code\planning.aspx.cs    Line: 265 

Stack Trace: 


[IndexOutOfRangeException: There is no row at position 255.]
   System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) +115
   System.Data.RBTree`1.get_Item(Int32 index) +19
   System.Data.DataRowCollection.get_Item(Int32 index) +12
   code_planning.btshow_click(Object sender, EventArgs e) in d:\Maestro\code\planning.aspx.cs:265
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +78
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +100
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2862



this error comes from the fact when I try to show a gridview whose data given by database.


could anyone tell what kind of error is this? how to solve it?

many thanks,
Posted
Updated 18-Jul-18 19:24pm
Comments
jessicachen12 13-Sep-12 11:28am
   
the error comes from Line 265.
[no name] 13-Sep-12 11:28am
   
The error is perfectly clear. Only try and show data for rows that actually exist. What seems to be the problem?
[no name] 13-Sep-12 11:41am
   
make sure that DataRowCollection is not empty.
sjelen 13-Sep-12 12:53pm
   
Since this is happening on postback, make sure you have populated datatable before reaching this code.
If you're not keeping datatable in Session, you'll need to fill it with data again on postback.
Provide more code using "Improve Question".

1 solution

[IndexOutOfRangeException: There is no row at position 255.]
There would be defined number of rows in your grid.

It looks like value of 's' is more then the row count.
C#
dt_gridcom.Rows[s][k] = summary;

Make sure that the row number that you are trying to access exists.
   

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