日期:2014-05-17 浏览次数:20558 次
//批量删除
        protected void btnAll_Click(object sender, ImageClickEventArgs e)
        {
            int items = rptCart.Items.Count;
            string[] goodsid = new string[99];
            for (int i = 0; i < items; i++)
            {
                bool flag = (rptCart.Items[i].FindControl("checkgood") as CheckBox).Checked;
                if (flag == true)
                {
                    goodsid[i] = (rptCart.Items[i].FindControl("btnDelete") as ImageButton).CommandArgument;
                }
            }
            for (int j = 0; j < goodsid.Length; j++)
            {
                if (goodsid[j] != null)
                {
                    DeleteGood(goodsid[j].ToString());
                }
            }
        }
------解决方案--------------------
获取选中checkbox的记录主要看红色标记部分,不要忘了在Page_Load事件里加IsPostBack判断
前台aspx页面: 一个checkbox  , 一个Label记录该条记录的ID
<asp:Repeater ID="Repeater2" runat="server">
                   <HeaderTemplate><ul class="ul_company"></HeaderTemplate>
                   <ItemTemplate><li style="margin:3px">
                        <asp:Label ID="Label2" runat="server" Text=<%#Eval("ID") %>  Visible="false"></asp:Label> <asp:CheckBox ID="CheckBox1" runat="server" /><%#Eval("CompanyName") %></li></ItemTemplate>                    <FooterTemplate></ul></FooterTemplate>
                   </asp:Repeater>
后台cs代码:
  按钮单击事件
 protected void Button3_Click(object sender, EventArgs e)
       {
           CheckBox CheckBox2;
           string idList = "";//用来存放选中的多条记录的ID
          
           for (int i = 0; i < Repeater2.Items.Count; i++)
           {
               CheckBox2 = (CheckBox)Repeater2.Items[i].FindControl("CheckBox1");
               if (CheckBox2.Checked == true)
               {
                 //如果选中 就取得该行的Label2标签的值,也就是该记录的ID
                   Label lbId = (Label)Repeater2.Items[i].FindControl("Label2");
               
                   idList = idList.Trim() + lbId.Text.ToString() + ",";
               }           
             
           }
           if (idList.Substring(idList.Length - 1) == ",")
           {
               idList = idList.Substring(0, idList.Length - 1);
           }
           string[] num = idList.Split(',');
           for (int j = 0; j < num.Length; j++)
           {
               long id = Convert.ToInt64(num[j]);
               string strWhere = "FeaturedId=" + id;
               List<CityHall.Model.T_Products> products = pbll.GetModelList(strWhere);
               foreach (CityHall.Model.T_Products t_product in products)
               {
                   t_product.FeaturedId = null;
                   pbll.Update(t_product);