您的位置:首页 > Web前端 > JQuery

使用jQuery方便的统计Repeater列的总和

2010-06-20 23:45 190 查看
<script type="text/javascript">
$(function () {
StatSum("lblAAcount", "spAAcount");
StatSum("lblBBcount", "spBBcount");
}
function StatSum(lblId, spId) {
var sum = 0;
$("span[id$='" + lblId +"']").each(function () {
sum += parseInt($(this).text());
});
$("#" + spId).text(sum);
}
</script>
<asp:Repeater ID="rptTest" runat="server" >
<HeaderTemplate>
<table>
<tr>
<th>年度</th>
<th>AA总人数</th>
<th>BB总人数</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("year")%></td>
<td><asp:Label runat="server" ID="lblAAcount" Text='<%#Eval("AAcount")%>'></asp:Label></td>
<td><asp:Label runat="server" ID="lblBBcount" Text='<%#Eval("BBcount")%>'></asp:Label></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>合计</td>
<td><span id="spAAcount"></span></td>
<td><span id="spBBcount"></span></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: