标签:
前台代码:
<asp:Repeater ID="rptList" runat="server">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
<tr>
<th width="8%">选择</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:CheckBox ID="chkId" CssClass="checkall" runat="server" style="vertical-align:middle;" />
<asp:HiddenField ID="hidId" Value=‘<%#Eval("id")%>‘ runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
后台代码:
1.绑定数据:
DataSet source = bll.GetList(.......);
rptList.DataSource = source;
rptList.DataBind();
2.操作 单选框
var selectCount=0;//选中了几个
var count=0;//选中值
for (int i = 0; i < rptList.Items.Count; i++)
{
int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);//隐藏域中的值
CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");//单选
if (cb.Checked)
{
selectCount++;
count+=id;
}
}
标签:
原文地址:http://www.cnblogs.com/change4now/p/4747578.html