ASP.NET中Gridview错误的RowIndex [英] RowIndex of Gridview Error in asp.net
本文介绍了ASP.NET中Gridview错误的RowIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在借助Checkbox实现批量删除功能.但是当我像下面那样拨打ID
I am implementing the bulk delete functionality with the help of Checkbox. But when I call the ID like below
string Id = grdUser.DataKeys[e.RowIndex].Value.ToString();
我收到错误信息
System.EventArgs不包含
RowIndex
的定义.
我不知道为什么会这样.请参阅我的代码以供参考:-
I dont know why it is happening. Please see my code for your reference:-
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvRow in grdUser.Rows)
{
CheckBox chkDelete = (CheckBox)grdUser.FindControl("chkDelete");
if (chkDelete.Checked)
{
string Id = grdUser.DataKeys[e.RowIndex].Value.ToString();
}
}
}
让我知道我必须做些什么改变
Do let me know what changes I have to make
推荐答案
您应按照Sandeep的说明添加 gvRow.RowIndex
.
You should add the gvRow.RowIndex
as stated by Sandeep.
然后,您必须像这样绑定网格视图.
Then you have to bind your gridview somewhat like this.
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvRow in grdUser.Rows)
{
if (gvRow.RowType == DataControlRowType.DataRow)
{
CheckBox chkDelete = (CheckBox)gvRow.FindControl("chkDelete");
if (chkDelete.Checked)
{
string Id = grdUser.DataKeys[gvRow.RowIndex].Value.ToString();
DeleteRecordByID(Id);
}
}
}
//Bind your Gridview here
}
让我知道它是否有效
这篇关于ASP.NET中Gridview错误的RowIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文