获取多个checkbox的值

 

 我前台绑定数据用了repeater控件   html代码是

<td><input type="checkbox" name="checkbox" value='<%#Eval("id") %>'/></td>

 我的方法是在前台用jq获取,代码如下

    <script>
        $(document).ready(function () {
            var mids = "";
            $("#ttt").click(function () {
                $("[name=checkbox]:checkbox:checked").each(function () {//遍历所有选中的checkbox
                    mids += "," + $(this).val();//结果可能为  ,1,2,3,4
                    location = "PayPage.aspx?ID=" + mids.substring(1);//因为获取到的第一个内容是“,” 所以用substring(1)去掉第一个结果,这样就剩下1,2,3,4了  然后传值到新的页面
                })
            })
        })
    </script>

 另一个页面后台接收ID

if (Request["ID"] != null)
{
  string sql = string.Format("select * from news where newsid in ({0})", Request["ID"].ToString());
}                        

posted @ 2014-12-30 16:58  laidanchao  阅读(362)  评论(0)    收藏  举报