多个check处理

1种:
前台:<div class="overdiv">                    
                                <asp:Repeater runat="server" ID="rpt_hobby">
                                    <HeaderTemplate><ol></HeaderTemplate>
                                    <ItemTemplate>
                                        <li><input type="checkbox" id="chkhobby" name="hobby" value='<%#Eval("id") %>'><%#Eval("val") %></li>
                                    </ItemTemplate>
                                    <FooterTemplate></ol> </FooterTemplate>
                                </asp:Repeater></div>
后台取值:
Request["hobby"]
2种:
前台: <div class="overdiv">                             
                <asp:Repeater runat="server" ID="rpt_hobby">
                    <HeaderTemplate><ol></HeaderTemplate>
                    <ItemTemplate>
                        <li><input type="checkbox" id="chkhobby"  runat="server" value='<%#Eval("id") %>'><%#Eval("val") %></li>
                    </ItemTemplate>
                    <FooterTemplate></ol> </FooterTemplate>
                </asp:Repeater></div>

后台赋值:
string hobbystr = dv[0].Row["hobby"].ToString();
                if (!string.IsNullOrEmpty(hobbystr))
                {
                    string[] hb = hobbystr.Split(',');
                    for (int i = 0; i < hb.Length; i++)
                    {
                        foreach (RepeaterItem rptitem in this.rpt_hobby.Items)
                        {
                            HtmlInputCheckBox chkhobby = (HtmlInputCheckBox)rptitem.FindControl("chkhobby");
                            if (chkhobby != null && chkhobby.Value == hb[i])
                            {
                                chkhobby.Checked = true;
                            }
                        }
                    }
                }
后台取值:
 string hobby = "";
        int currentnum = 0;
        foreach (RepeaterItem rptitem in this.rpt_hobby.Items)
        {
            HtmlInputCheckBox chkhobby = (HtmlInputCheckBox)rptitem.FindControl("chkhobby");
            if (chkhobby != null && chkhobby.Checked)
            {
                if (currentnum > 0)
                    hobby += ",";
                hobby += chkhobby.Value;
                currentnum++;
            }
           
        }
posted @ 2009-08-05 09:01  94cool  阅读(209)  评论(0)    收藏  举报