如何在行命令事件中从 gridview 中删除行? [英] How to remove row from gridview on row command event?
本文介绍了如何在行命令事件中从 gridview 中删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过单击位于 gridview 中的 ImageButton 从 gridview 中删除行.我正在获取行索引,但不知道如何删除.我的 gridview 从会话绑定,我不想重新绑定 gridview.
I am trying to remove row from gridview by click on ImageButton which is placed inside gridview. I am getting row index but dont know how to remove. My gridview binds from session and i dont want to rebind gridview.
这是我的代码:
protected void GVDetail_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Remove"))
{
List<Class1> list = (List<Class1>)Session["value1"];
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gridRow = gvDetail.Rows[index];// (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
((List<Class1>)Session["value1"]).RemoveAt(index);
}
}
如果有人对此有任何想法,请帮助我..
If anyone have any idea about this than please help me..
推荐答案
使用 gridview deleterow 方法.
Use the gridview deleterow method.
void GVDetail_RowCommand_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="Remove")
{
var id = Int32.Parse(e.CommandArgument);
GVDetail.DeleteRow(id);
}
}
这篇关于如何在行命令事件中从 gridview 中删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文