指定的参数已超出有效值的范围。参数名: index
在CSDN上搜索到同样的问题有3个,跟帖的人不少,但是没有能给给出解决方法,在此再帖出来让大家讨论一下怎么解决.
在做DataGrid的编辑时遇到的问题,点击"更新"就弹出这个错误:
异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。参数名: index
源错误:
行 145: string ID=e.Item.Cells[0].Text.ToString();
行 146: Label1.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text.ToString();
//下面两行都是正确的,就是上面这行(行 146:)有问题
//Label1.Text=((TextBox)e.Item.Cells[0].Controls[0]).Text.ToString();
//Label1.Text=((TextBox)e.Item.Cells[2].Controls[0]).Text.ToString();
源文件: e:\asp.net应用程序\cyt\admin_searchfile.aspx.cs 行: 146
我的代码如下(点击"更新"时触发):
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string dsn=ConfigurationSettings.AppSettings["DSN"];
SqlConnection Conn=new SqlConnection(dsn);
Conn.Open();
//获取相应行的相应字段值
string ID=e.Item.Cells[0].Text.ToString();
Label1.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text.ToString();
/*
string number=((TextBox)e.Item.Cells[1].Controls[0]).Text.ToString();
string name=((TextBox)e.Item.Cells[2].Controls[0]).Text.ToString();
string page=((TextBox)e.Item.Cells[3].Controls[0]).Text.ToString();
string time=((TextBox)e.Item.Cells[4].Controls[0]).Text.ToString();
//更新数据
string Sql="update text set number='"+number+"',text='"+name+"',page_num='"+page+"',release_time='"+time+" where id="+ID;
SqlCommand Comm=new SqlCommand(Sql,Conn);
Comm.ExecuteNonQuery();
DataGrid1.EditItemIndex=-1; //禁止用户编辑DataGrid
BindGrid(); //重新填充
*/
Conn.Close();
}
在做DataGrid的编辑时遇到的问题,点击"更新"就弹出这个错误:
异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。参数名: index
源错误:
行 145: string ID=e.Item.Cells[0].Text.ToString();
行 146: Label1.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text.ToString();
//下面两行都是正确的,就是上面这行(行 146:)有问题
//Label1.Text=((TextBox)e.Item.Cells[0].Controls[0]).Text.ToString();
//Label1.Text=((TextBox)e.Item.Cells[2].Controls[0]).Text.ToString();
源文件: e:\asp.net应用程序\cyt\admin_searchfile.aspx.cs 行: 146
我的代码如下(点击"更新"时触发):
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string dsn=ConfigurationSettings.AppSettings["DSN"];
SqlConnection Conn=new SqlConnection(dsn);
Conn.Open();
//获取相应行的相应字段值
string ID=e.Item.Cells[0].Text.ToString();
Label1.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text.ToString();
/*
string number=((TextBox)e.Item.Cells[1].Controls[0]).Text.ToString();
string name=((TextBox)e.Item.Cells[2].Controls[0]).Text.ToString();
string page=((TextBox)e.Item.Cells[3].Controls[0]).Text.ToString();
string time=((TextBox)e.Item.Cells[4].Controls[0]).Text.ToString();
//更新数据
string Sql="update text set number='"+number+"',text='"+name+"',page_num='"+page+"',release_time='"+time+" where id="+ID;
SqlCommand Comm=new SqlCommand(Sql,Conn);
Comm.ExecuteNonQuery();
DataGrid1.EditItemIndex=-1; //禁止用户编辑DataGrid
BindGrid(); //重新填充
*/
Conn.Close();
}
...全文
相关推荐
pandas中DataFrame修改index、columns名的方法示例
主要介绍了pandas中DataFrame修改index、columns名的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
python 给DataFrame增加index行名和columns列名的实现方法
今天小编就为大家分享一篇python 给DataFrame增加index行名和columns列名的实现方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
pytorch获取模型某一层参数名及参数值方式
今天小编就为大家分享一篇pytorch获取模型某一层参数名及参数值方式,具有很好的价值,希望对大家有所帮助。一起跟随小编过来看看吧
Python pandas.DataFrame调整列顺序及修改index名的方法
主要介绍了Python pandas.DataFrame调整列顺序及修改index名的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Android应用因索引超出范围问题而崩溃。 请帮我解决这个问题
Android仍基于Java语言,因此例外通常是应用程序中以Java为主题的问题。 “索引超出范围”表示您正在尝试引用当前集合内不可用的元素。 看看异常本身,索引...


