.Net實現的大量刪除(使用了repeater控制項)

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   os   使用   sp   for   

前台

 <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;                }            }        }

 

.Net實現的大量刪除(使用了repeater控制項)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.