注册 登录
编程论坛 ASP.NET技术论坛

girdview的问题

刘小芳 发布于 2007-08-03 11:11, 703 次点击

“/jhzz”应用程序中的服务器错误。
--------------------------------------------------------------------------------

索引超出范围。必须为非负值并小于集合大小。
参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index

源错误:


行 120: protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
行 121: {
行 122: GridViewRow gvr = GridView1.Rows[e.NewSelectedIndex];
行 123: this.txt_ddjd.Text = gvr.Cells[8].Text;
行 124: this.txt_ydza.Text = gvr.Cells[9].Text;


怎么回事呀,以前就没错过

6 回复
#2
cyyu_ryh2007-08-03 11:29
this.txt_ddjd.Text = GridView1.SelectRow.Cells[8].Text;
#3
洁洁2007-08-03 11:30
以前没错过,只能说明没出现过现在的运行情况,但是并不能说明没有这样的隐患
#4
jyoseyi2007-08-03 12:11

插断点跟踪下

#5
冰彩虹2007-08-03 12:26

不会吧,是不是选择的行的RowType有问题哈

#6
hinroe2007-08-03 14:24

我也跟楼主一样遇到同样的问题提示,就是“索引超出范围。必须为非负值并小于集合大小。参数名: index”

if (id > 0) //修改
{
DetailsViewFile.DataSource = MediaFile.GetListByCategoryID(id);
DetailsViewFile.DataBind();
MediaFile file = new MediaFile(id);
MediaCategories category = new MediaCategories(file.CategoryID);
DropDownList ddl = (DropDownList)DetailsViewFile.Rows[0].FindControl("dropCategory");
ddl.DataSource = MediaCategories.GetInfoByCategoryID(category.ParentID);
ddl.DataBind();
ddl.SelectedValue = file.CategoryID.ToString();
ViewState.Add("cid",cid);

}

else //添加
{
MediaCategories category = new MediaCategories(cid);
DetailsViewFile.DefaultMode = DetailsViewMode.Insert;
DropDownList ddl = (DropDownList)DetailsViewFile.Rows[0].FindControl("dropCategory");
if (category.Level == 1)
{
ddl.DataSource = MediaCategories.GetInfoByCategoryID(cid);
ddl.DataBind();
}
else
{
ddl.DataSource = MediaCategories.GetInfoByCategoryID(category.ParentID);
ddl.DataBind();
ddl.SelectedValue = category.CategoryID.ToString();
}
}

我设断点了,可运行到红字之前都可以,一到红字那就提示问题了,不知道怎么弄了,帮看看吧!好长时间没解决这个问题了,都愁死了,借楼主的地盘问个问题,重在解决问题,请见谅!

#7
sean882007-08-03 14:44
加上这个试试:
if(DetailsViewFile.Item.ItemType == ListItemType.Item ||DetailsViewFile.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddl = (DropDownList)DetailsViewFile.Rows[0].FindControl("dropCategory");
}
1