无法从gridview中删除行 [英] cannot delete row from gridview

查看:88
本文介绍了无法从gridview中删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从gridview中删除行但是当它运行并按下删除按钮时,没有任何反应:

  protected   void  GridView1_RowCommand( object  sender,GridViewCommandEventArgs e)
{
if (e.CommandName.Equals( 删除))
{
int index = Convert.ToInt32(e.CommandArgument);
var id =((Label)GridView1.Rows [index] .Cells [ 0 ] .FindControl( id))。Text.Trim();

SqlConnection con = new SqlConnection(connstring);
string qry = 从['删除ISB VAS节点$']其中ID = + id + ;
SqlCommand com = new SqlCommand(qry,con);

if (com.ExecuteNonQuery()== 1
{
Label2.Text = 已删除;
binddata();
}
else
{
Label2.Text = 未删除;
}
}
}

解决方案

']其中ID = + id + ;
SqlCommand com = 新的 SqlCommand(qry,con);

if (com.ExecuteNonQuery()== 1
{
Label2.Text = 已删除;
binddata();
}
else
{
Label2.Text = < span class =code-string> 未删除;
}
}
}


I''m trying to delete row from gridview but when it runs and I press delete button, nothing happens:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("Delete"))
    {
       int index = Convert.ToInt32(e.CommandArgument);
       var id = ((Label)GridView1.Rows[index].Cells[0].FindControl("id")).Text.Trim();

       SqlConnection con = new SqlConnection(connstring);
       string qry = "Delete from ['ISB VAS Nodes$'] where ID = " + id + "";
       SqlCommand com = new SqlCommand(qry, con);

       if (com.ExecuteNonQuery() == 1)
       {
           Label2.Text = "Deleted";
           binddata();
        }
        else
        {
           Label2.Text = "Not Deleted";
        }
     }
}

解决方案

'] where ID = " + id + ""; SqlCommand com = new SqlCommand(qry, con); if (com.ExecuteNonQuery() == 1) { Label2.Text = "Deleted"; binddata(); } else { Label2.Text = "Not Deleted"; } } }


这篇关于无法从gridview中删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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