<asp:Repeater ID="rep" runat="server">
    <ItemTemplate>
        <div>
        <asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
        <asp:CheckBox ID="cbXuan" Text="选中" runat="server" />
        </div>
    </ItemTemplate>
</asp:Repeater><asp:Button ID="btnShanChu" runat="server" Text="删除所有选中" OnClick="btnShanChu_Click" />请问当我点删除后,如何在后台btnShanChu_Click里如何获取我选中的哪些的ID了?

解决方案 »

  1.   

     //全选和全不选的js脚本    function SelectAllCheckboxes(theBox)
        {
         var xState=theBox.checked;
         elm=theBox.form.elements;
         for(i=0; i < elm.length;i++)
         if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
         {
           if(elm[i].checked!=xState)
           elm[i].click();
         }
        }//cs中处理选中行的例子
     protected void lkDeal_Click(object sender, EventArgs e)
        {
            string ZFX = "N";
            if (((LinkButton)sender).Text == "还原")
                 ZFX = "Y";        StringBuilder S = new StringBuilder();
            foreach (GridViewRow gvr in gvMain.Rows)
            {
                //CheckBox chk = (CheckBox)gvr.Cells[0].Controls[0];
                CheckBox chk = (CheckBox)gvr.Cells[0].FindControl("chk");            if (chk.Checked)
                {
                    S.AppendFormat("{0},", gvr.Cells[1].Text);
                }
            } 
            if (S.Length > 0)
            {
                string SQL = S.ToString();
                SQL = SQL.Remove(SQL.Length - 1, 1);
                SQL = string.Format("UPDATE TD_CONSUMER SET ZFX='{0}' WHERE ZID IN({1})", ZFX, SQL);
                if (MsSqlHelper.ExecuteNonQuery(SQL) > 0)
                    Response.Redirect(Request.Url.ToString());
            }
        }
      

  2.   

      protected void btnShanChu_Click(object sender, EventArgs e)
        {      SqlConnection  conn = new SqlConnection(str_con):
            foreach (RepeaterItem item in Repeater1.Items)
            {
                CheckBox cb = (CheckBox)item.FindControl("cbXuan");
                if (cb.Checked == true)
                {
                    Label lab = (Label)item.FindControl("lblID");
                    sql = "delete table where id='" + lab.Text + "' ";
                    conn.Open();
                    cmd = new SqlCommand(sql, conn);
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
            Response.Redirect(Request.Url.ToString());//刷新页面,跟新页面信息
        }
      

  3.   

    没有注释,解释下刚才的例子的作用:
    作用:对选中行的ZFX字段置为'Y' 或者'N'.
    如果联结的标签是 "还原"则置为'Y' ,否则置为'N' 
      

  4.   


    foreach (RepeaterItem Item in rep.Items)

           Label lbl = (Label)Item.FindControl("lblID");
           CheckBox chk= (CheckBox)Item.FindControl("cbXuan");
           if(chk.Checked)
           {
                string id = lbl.Text;
                ............
            }
    }