标题:asp.net gridview 删除CheckBox选中记录无反应(页面只是刷新一下,没有删除 ...
只看楼主
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
结帖率:71.43%
 问题点数:0 回复次数:0 
asp.net gridview 删除CheckBox选中记录无反应(页面只是刷新一下,没有删除)
删除按钮代码
 string sql = "";
        string connString = ConfigurationManager.ConnectionStrings["sjlj"].ToString();
        SqlConnection conn = new SqlConnection(connString);
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                sql = "delete from rkb where id='" + GridView1.DataKeys[i].Value + "'";
                conn.Open();
                SqlCommand com = new SqlCommand(sql, conn);
                com.ExecuteNonQuery();
                conn.close();

            }
        }
        sjdq();
数据库读取代码
public void sjdq()
    {
        string connString = ConfigurationManager.ConnectionStrings["sjlj"].ToString();
        SqlConnection con = new SqlConnection(connString);
        con.Open();
        string sql = "select * from rkb order by 日期";
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = new SqlCommand(sql, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.AllowPaging = true;
        GridView1.PageSize = 5;
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
        con.Close();
    }
搜索更多相关主题的帖子: where 记录 
2016-12-23 09:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-472800-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015170 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved