• DataGrid 中使用 复选框(CheckBox) 删除纪录





    在DataGrid中加入模板列加入Label用以表示该纪录编号(id)

    然后再用模板列制作删除列 插入复选框 checkbox

    删除按钮的代码如下:

    public void btnDel_Click(object sender,EventArgs e)
            
    {
                
    //要删除的id号
                string strId="";
                
    foreach(DataGridItem i in DataGrid1.Items)
                
    {
                    
                    CheckBox chk
    =(CheckBox)i.FindControl("CheckBox1");
                    
    if(chk.Checked)
                    
    {
                        
    //查找该CheckBox所对应纪录的id号,在Label2中
                        strId+=((Label)i.FindControl("Label2")).Text+",";                        
                    }


                }

                
    if(strId.Length>1)
                
    {
                    
    //去掉最后的一个逗号
                    strId=strId.Substring(0,strId.Length-1);
                    
    string sql="delete from Dif_Info where [id] in (" +strId + ")";
                    db.RunProc(sql);
                    Response.Write(
    "<script language=javascript>window.alert('操作成功');</script>");
                    BindGrid();
                }

                
            }


    在html页中加入按钮方法

    <asp:Button id="btnDel" onclick="btnDel_Click" runat="server" Text="删除"></asp:Button>

    完成

  • 相关阅读:
    RESTful规范1
    Django -- 发送HTML格式的邮件
    11.10 vue
    Selenium 使用
    Beautiful Soup的用法
    Pthon常用模块之requests,urllib和re
    爬虫--工具安装Jupyter anaconda
    11-3
    Python -- tabulate 模块,
    Python -- queue队列模块
  • 原文地址:https://www.cnblogs.com/dekevin/p/2484647.html
Copyright © 2020-2023  润新知