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++;
}
}
前台:<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++;
}
}
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2009/08/05/1539227.html,如需转载请自行联系原作者