Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I found the error
There is no row at position 1. index
My code is:

C#
GridViewRow row = GridView1.Rows[e.RowIndex];
if (Session["dt"] != null)
        {
            DataSet dt1 = (DataSet)Session["dt"];
          dt1.Tables[0].Rows[row.DataItemIndex][0] = ((TextBox)(row.Cells[1].Controls[0])).Text;
            dt1.Tables[0].Rows[row.DataItemIndex][1] = ((TextBox)(row.Cells[2].Controls[0])).Text;
            dt1.Tables[0].Rows[row.DataItemIndex][2] = ((TextBox)(row.Cells[3].Controls[0])).Text;
            dt1.Tables[0].Rows[row.DataItemIndex][3] = ((TextBox)(row.Cells[4].Controls[0])).Text;
            GridView1.EditIndex = -1;
            binddata();
        }
        if (Session["key"] != null)
        {
            Response.Write("hello");
            DataSet dt2 = (DataSet)Session["key"];
           // GridViewRow row1 = GridView1.Rows[e.RowIndex];
            dt2.Tables[0].Rows[row.DataItemIndex][0] = ((TextBox)(row.Cells[1].Controls[0])).Text;
            dt2.Tables[0].Rows[row.DataItemIndex][1] = ((TextBox)(row.Cells[2].Controls[0])).Text;
            dt2.Tables[0].Rows[row.DataItemIndex][2] = ((TextBox)(row.Cells[3].Controls[0])).Text;
            dt2.Tables[0].Rows[row.DataItemIndex][3] = ((TextBox)(row.Cells[4].Controls[0])).Text;
            GridView1.EditIndex = -1;
            binddata();
        }

The second sesssion part is not working. The error occured in the second session part. the first part is working well. dt1.Tables[0].Rows[row1.DataItemIndex][0] = ((TextBox)(row1.Cells[1].Controls[0])).Text;Any suggestion please.
Posted
Updated 5-Feb-11 3:37am
v11
Comments
RaviRanjanKr 5-Feb-11 0:20am    
Please Wrap your code in "Pre" tags to make it readability

Since you haven't given us any usable info to work with, we have to guess.

My first guess is that row1 e.RowIndex is outside the range of GridView.Rows.

Have you considered putting a try/catch block around the code to see if it tells you what's wrong?
 
Share this answer
 
It's likely to be something in your dt2 DataSet

Is dt2.Tables[0] valid? Is there definitely a DataTable at this index?
If there is a table, is there a row in dt2 at the specified index? row1.DataItemIndex?
If there is a row, does it have all the fields you've specified?!

Using your debugger, you should be able to determine which of these are invalid.
 
Share this answer
 
The event e is apparantely be set for the first dataset but not the second - this could be what is throwing the error.

It is probably that you have fired e based on the first dataset and not the second.
 
Share this answer
 
v2
Comments
gowdhami 5-Feb-11 0:17am    
i used event e at once but from second row the updation is not happening.. showing the error there is no row at position 1
I suppose,when the first part gets executed a post back occurs & you are losing the RowIndex or the Row itself which results in the exception.Either you can persist the row in a ViewState or the rowindex in hiddenfield & utilize that.Put a debugger,watch & see if any of the value is becoming null and handle accordingly.
 
Share this answer
 

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