zoukankan      html  css  js  c++  java
  • .Net实现的批量删除(使用了repeater控件)

    前台

     <asp:Repeater ID="Repeater1" runat="server">
                <HeaderTemplate>
                    <table>
                        <tr>
                            <td>选择</td>
                            <td>姓名</td>
                            <td>密码</td>
                        </tr>
                    
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><input id="CKChance" runat="server" type="checkbox" value='<%#Eval("AdminId") %>'/></td>
                        <td><%#Eval("AdminName") %></td>
                        <td><%#Eval("AdminPwd") %></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
           
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

    后台:

     protected void Page_Load(object sender, EventArgs e)
            {
                if(!IsPostBack)
                {
                    GetDate();
                }
            }
    
            public void GetDate() 
            {
                string ConStr = "Data Source=.;Initial Catalog=UserSystem;Integrated Security=True";
                using (SqlConnection conn = new SqlConnection(ConStr))
                {
                    string sql = "SELECT * FROM ADMIN";
                    //SqlCommand comm = new SqlCommand(sql.ToString(),conn);
                    DataSet dt = new DataSet();
                    SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
                    sda.Fill(dt);
                    DataTable dtl = dt.Tables[0];
                    //dt.Tables.Add(dtl);
                    this.Repeater1.DataSource = dtl;
                    this.Repeater1.DataBind();
                }
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                DelInfo(); 
            }
    
            public void DelInfo() 
            {
                string j=string.Empty;
    
                for (int i = 0; i < this.Repeater1.Items.Count;i++ )
                {
                    HtmlInputCheckBox cbox = (HtmlInputCheckBox)this.Repeater1.Items[i].FindControl("CKChance");
                    if(cbox.Checked==true)
                    {
                        j+=cbox.Value+",";                  
                    }
                }
                j = (j + "").Replace(",!","");
                string ConStr = "Data Source=.;Initial Catalog=UserSystem;Integrated Security=True";
                using (SqlConnection conn = new SqlConnection(ConStr))
                {
                    conn.Open();
                    string delsql = "DELETE FROM [Admin] WHERE AdminId in (" + j + ")";
                    SqlCommand comm = new SqlCommand(delsql.ToString(), conn);
                    if (comm.ExecuteNonQuery() > 0)
                    {
                        GetDate();
                       //Response.Write("<script>alert('删除成功')</script>");
                    }
                    else
                    {
                        //return false;
                    }
                }
    
            }
  • 相关阅读:
    Eclipse for j2ee 无法调式问题
    Windows Redis安装,Java操作Redis
    Java Junit单元测试
    Spring 学习总结 使用静态工厂创建Bean
    JQuery AJAX 解析获得的JSON数据
    Spring中的ApplicationContext事件机制
    Android 扫一扫----ZXing 的使用
    Window环境下 Git 下载Android源码
    JAVA单向/双向链表的实现
    Activity和Service是否是在同一个进程中运行。
  • 原文地址:https://www.cnblogs.com/llcdbk/p/4116243.html
Copyright © 2011-2022 走看看