位置1没有行. [英] There is no row at position 1.
本文介绍了位置1没有行.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了错误
在位置1处没有行.索引
我的代码是:
GridViewRow row = GridView1.Rows [e.RowIndex];
如果(会话[" ] != 为空)
{
DataSet dt1 =(DataSet)Session [" ];
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();
}
如果(会话[" ] != 为空)
{
Response.Write(" );
DataSet dt2 =(DataSet)Session [" ];
// 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();
}
第二会话部分不起作用.错误发生在第二个会话部分.第一部分运作良好. dt1.Tables [0] .Rows [row1.DataItemIndex] [0] =((TextBox)(row1.Cells [1] .Controls [0])).Text;请提出任何建议.
解决方案
由于您没有给我们提供任何有用的信息,我们不得不猜测.
我的第一个猜测是row1e.RowIndex
在GridView.Rows
的范围之外.
您是否考虑过在代码周围放置try/catch块,看看它是否告诉您什么地方不对?
这可能是您的dt2 DataSet中的内容
dt2.Tables [0]有效吗?在这个索引上肯定有一个DataTable吗?
如果有表,则dt2中指定索引处是否存在一行? row1.DataItemIndex?
如果有一行,它是否具有您指定的所有字段?!
使用调试器,您应该能够确定其中哪些无效.错误.
可能您是根据第一个数据集而不是第二个数据集触发了e.
I found the error
There is no row at position 1. index
My code is:
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.
解决方案
Since you haven''t given us any usable info to work with, we have to guess.
My first guess is that row1e.RowIndex
is outside the range ofGridView.Rows
.
Have you considered putting a try/catch block around the code to see if it tells you what''s wrong?
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.
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.
这篇关于位置1没有行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文