我想在按钮点击时删除gridview行 [英] I want to delete gridview row on button click

查看:52
本文介绍了我想在按钮点击时删除gridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码正在使用其他系统visual studio,但我的系统无法运行



this code is working other system visual studio but my system is not working

protected void Button1_Click1(object sender, EventArgs e)
{
    foreach (GridViewRow gdv in GridView1.Rows)
    {
        CheckBox chk = (gdv.Cells[0].FindControl("chkbox1") as CheckBox);

        if (chk.Checked == true)
        {
            var Label = gdv.Cells[0].FindControl("lblid") as Label;
            SqlConnection cn = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand("Delete from tbl_login where Id=@Id", cn);
            cmd.Parameters.AddWithValue("@Id", int.Parse(Label.Text));
            cn.Open();
            int id = cmd.ExecuteNonQuery();
            cn.Close();

            Gridviewdetail();
        }

    }
}



此代码是我的系统无法使用

检查复选框总是如此错误为什么

checkBok检查不显示'true'

如果关于复选框上删除行的另一个想法检查,那么plz帮助我。只有按钮活动



我尝试过:



plz帮帮我先生

为什么显示总是错误复选框选中


this code is my system is not working
checkBox checked is always so 'False' why
checkBok Checked is not show 'true'
if another idea about delete row on checkBox Check so plz help me. only button event

What I have tried:

plz help me sir
why show always false checkbox checked

推荐答案

使用ASP.Net C#从Gridview删除多个记录 [ ^ ]


google上有很多答案。

这里有一些参考资料



Link 1




Link 2




Link 3



最好花一些时间来理解代码逻辑。
There are lots of answer available on google.
Here is some references

Link 1


Link 2


Link 3

Better to spend some time to understand code logic.


这篇关于我想在按钮点击时删除gridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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