从GridView删除问题 [英] deleting problem from gridview
本文介绍了从GridView删除问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从gridview删除行时,出现错误-索引超出范围.必须为非负数并且小于集合的大小.
参数名称:索引我有一个代码-
when i am deleting the row from gridview then getting errors-Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index i have a code-
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string autoID = GridView1.DataKeys[e.RowIndex].Value.ToString();
SqlConnection con = ConnectionClass.GetConnection();
SqlCommand cmd=new SqlCommand("delete from information where id='"+ Convert.ToInt32(autoID) + "'", con);
cmd.ExecuteNonQuery();
con.Close();
ShowData();
}
请给我一个解决方案
Plz give me a solution
推荐答案
带有确认的GridView删除 [ ^ ]
使用Gridview插入,更新,删除....简单方式 [ ^ ]
使用GridView控件更新,删除记录 [ GridView行编辑,删除和更新 [ ^ ]
插入更新编辑删除行记录在GridView中 [
GridView Delete, with Confirmation[^]
Insert, Update, Delete with Gridview....simple way[^]
Updating, Deleting records using GridView control[^]
GridView Row Edit, Delete and Update[^]
Insert Update Edit Delete Rows Record In GridView[^]
整数值不必''''
Integer value need not''''
SqlCommand cmd=new SqlCommand("delete from information where id="+ Convert.ToInt32(autoID) + "", con);
您是否已检查autoID
的值
请使用DEBUGGER
检查autoID
的值.
谢谢
Ashish
Have you checked the value of autoID
Please check the value of autoID
by using DEBUGGER
.
Thanks
Ashish
我认为您为此网格视图定义了多个数据键
DataKeyName="autoID,anotherColumn"
如果是这种情况,请尝试在代码中指定键的索引,如下所示
I think you have multiple datakeys defined for this gridview
DataKeyName="autoID,anotherColumn"
If this is your case then try specifying the index of the key in your code like below
GridView1.DataKeys[e.RowIndex].Value[0].ToString();
>
这篇关于从GridView删除问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文