在Repeater中选中多个checkbox,然后点击删除按钮.如何循环删除?以下是部分代码..
for (int i = 0; i < Repeater.Items.Count; i++)
        {
            CheckBox cb = (CheckBox)engineer_Repeater.Items[i].FindControl("checkbox1");
            if (cb.Checked)
            {
                Label lb = (Label)engineer_Repeater.Items[i].FindControl("label1");
}
}

解决方案 »

  1.   

    for (int i = 0; i < Repeater.Items.Count; i++)
    {
    CheckBox cb = (CheckBox)engineer_Repeater.Items[i].FindControl("checkbox1");
    if (cb.Checked)
    {
    Label lb = (Label)Repeater.Items[i].FindControl("label1");
    }
    }
      

  2.   

    删除无选中的多条记录,label1为主键ID绑定
      

  3.   

    删除选中的多条记录,label1为主键ID绑定
      

  4.   

    把要删除的主键取出来中间用逗号分开
    delete table where id in(主键)
      

  5.   


    把要删除的主键取出来中间用逗号分开
    delete table where id in(主键)===============================说的不错,你现在只要把需要删除的那些 ID取出来 组成'aa','bb','cc'的字符串 然后就可以执行了
      

  6.   

    获取未选中项ID放到ArryList列表中 在后台使用 delete table where id in(主键) sql语句删除即可
      

  7.   

    同意igelf,定义变量将id用","号拼起来
    再执行sql语句delete from table where id in(变量)
      

  8.   

    or (int i = 0; i < Repeater.Items.Count; i++)
    {
    CheckBox cb = (CheckBox)engineer_Repeater.Items[i].FindControl("checkbox1");
    if (cb.Checked)
    {
    Label lb = (Label)engineer_Repeater.Items[i].FindControl("label1");
    // 可以先隐藏删除了的行
    Repeater.Items[i].Visiable = false;
    }
    }
      

  9.   

    需要删除的那些 ID取出来 组成'aa','bb','cc'的字符串 然后就可以执行了
      

  10.   

    private void btnDelete_Click(object sender, System.EventArgs e)
    {
    bool flag = false;
    for(int i = 0;i<Grid.Items.Count;i++)
    {
    CheckBox check = (CheckBox)Grid.Items[i].FindControl("cb");
    if (check.Checked)
    {
    string id = Grid.Items[i].Cells[0].Text;
    User.Id = int.Parse(id.ToString());
    User.AdminDelUser();
    flag = true;
    }
    }

    chkSelect.Checked = false;
    if (flag)
    {
    Response.Write("<script>alert('删除成功');window.location.href='"+this.Request.RawUrl+"';</script>");
    if (Grid.CurrentPageIndex>0)
    Grid.CurrentPageIndex--;
    BindGrid();
    }

    else
    Response.Write("<script>alert('没有选择要删除的数据');</script>"); }
      

  11.   

    CheckBox chkID = null;
    int ID = 0;
    foreach(DataGridItem dgItem in this.DataGrid1.Items)
    {
    chkID = (CheckBox)dgItem.FindControl("RowSelecter");
    if(chkID.Checked)
    {
    ID=(int)this.DataGrid1.DataKeys[(int)dgItem.ItemIndex];
    DataAccess.ExcuteCmd("DELETE FROM GroupContact WHERE id="+ID);
    }
    }
      

  12.   

    把要删除的主键取出来中间用逗号分开
    delete table where id in(主键)
    ------------------------------
    怎样取?我只能取到一个,如果选的多条记录,怎么取?
      

  13.   

    string sql = "delete from table where id in ({0})";
    ArrayList list = new ArrayLIst();
    for (int i = 0; i < Repeater.Items.Count; i++)
    {
    CheckBox cb = (CheckBox)engineer_Repeater.Items[i].FindControl("checkbox1");
    if (cb.Checked)
    {
    Label lb = (Label)Repeater.Items[i].FindControl("label1");
    list.Add(lb.Text);
    }
    }string[] strDel = list.ToArray(typeof(string)) as String[];
    if(strDel.length > 0){
      sql = string.Format(sql,string.Join(",",strDel));
      //执行sql
    }
      

  14.   

    把要删除的主键取出来中间用逗号分开
    delete table where id in(主键)
    ------------------------------
    怎样取?我只能取到一个,如果选的多条记录,怎么取?
    ===============================================
    把主键设为DataKeyField
    string vStr="";
      for (int i = 0; i < Repeater.Items.Count; i++)
    {
    CheckBox cb = (CheckBox)engineer_Repeater.Items[i].FindControl("checkbox1");
    if (cb.Checked)
    {
    vStr.Append(engineer_Repeater.DataKeys[i].ToString());
     vStr.Append(",");Label lb = (Label)Repeater.Items[i].FindControl("label1");
    list.Add(lb.Text);
    }
    }}
     多选的checkbox删除的SQL:sql="delete table where id in (" + vStr + "1)";
      

  15.   

    上面修改一下
    string vStr="";
    改为StringBuilder vStr = new StringBuilder("");
      

  16.   

    你想删什么啊,想删数据库记录,上面有人说了
    把你选中的值得出来,做成string ids="‘1’,‘2’,‘3’"样式
    放到
    delete from tablename where id in(ids)不就完了吗得ID的值,遍历一下Repeater就行了个人见解,共同学习
      

  17.   

    bool result = roleBL.UpdateRole(role);
            if (result)
            {
                for (int i = 0; i < cblFunctionName.Items.Count; i++)
                {
                    if (roleFunctionBL.SelectRoleFunctions(Convert.ToInt32(cblFunctionName.Items[i].Value), RoleId) > 0)//是否存在
                    {
                        if (!cblFunctionName.Items[i].Selected)
                        {
                            roleFunctionBL.DeleteRoleFunction(RoleId, Convert.ToInt32(cblFunctionName.Items[i].Value));//存在就删除
                        }
                    }
                    else
                    {
                        if (cblFunctionName.Items[i].Selected)
                        {
                            roleFunctionBL.InsertIdRoleFunction(RoleId, Convert.ToInt32(cblFunctionName.Items[i].Value));//没有就添加
                        }
                    }
                }
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('更新成功!');Exit();</script>");
            }
            else
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('更新失败!');Exit();</script>");
            }
        }