如何从行命令事件的GridView删除行? [英] How to remove row from gridview on row command event?

查看:89
本文介绍了如何从行命令事件的GridView删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过点击的ImageButton被安置里面的GridView 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.

下面是我的code:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆