把CheckBox的值封装成数组形式传递到第二个页面

前端我用repeater控件里装着一个CheckBox:  <asp:CheckBox ID="cbx_Complete" runat="server" AutoPostBack="true" ValidationGroup='<%#Eval("MemberAddress_Id") %>'/>;还有一个保存按钮,在repeater控件外的

后台第一个页面接收之后,封装数组的方式,写在按钮事件里面

string ids = "";
            for (int i = 0; i < rptItems.Items.Count; i++)
            {
                //找到相应的Checkbox控件   
                CheckBox cb = (CheckBox)rptItems.Items[i].FindControl("cbx_Complete");
                //获取id并连接成字符串,用,分隔   
                if (cb != null)
                {
                    string selectedId = cb.ValidationGroup;
                    if (cb.Checked)
                    {
                        ids += selectedId + ",";
                    }
                }
            }
            //处理末尾的,   
            if (ids.Contains(","))
            {
                ids = ids.Substring(0, ids.Length - 1);
            }

跳转到第二个页面接收ID的方式:

分割数组:

string [] ids = Request.QueryString["id"].Split(',');
                foreach (var item in ids)
                {
                    string s = item.ToString();
                    if (s != "")
                    {
                        //去掉前缀
                        s = s.Replace("undefined", "\\");
                        int lenth = s.Length - s.LastIndexOf("\\") - 1;
                        s = s.Substring(s.LastIndexOf("\\") + 1, lenth);
                         }
此时s的值就是第一页传过来的ID了
           

posted @ 2014-09-19 16:12  与众不同  阅读(441)  评论(0编辑  收藏  举报