asp.net repeater统计表某列值

方式一

decimal sum = 0;  

  protected void RepMain_ItemDataBound(object sender, RepeaterItemEventArgs e)  

  {  

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)  

    {  

    string num = DataBinder.Eval(e.Item.DataItem, "DXFY").ToString().Trim();  

    if (!num.Equals(""))  

            sum += Convert.ToDecimal(num);  

     }  

            this.lblSum.Text = sum.ToString() + "元";  

 }  

 

方式二

<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>

 

方式三

 
如何使用js对Repeater生成的table进行列和统计?
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse; width:400px;">
  <tr align="center" style="height:25px;">
  <th style="width:50px; line-height:120%;">序号</th>
  <th style="width:150px; line-height:120%;">样文</th>
  <th style="width:200px; line-height:120%;">录入列</th>
  </tr>

  <asp:Repeater ID="Repeater1" runat="server" 
  onitemdatabound="Repeater1_ItemDataBound">
  <ItemTemplate>
  <tr align="right" style="height:25px;">
  <td align="center"><%# DataBinder.Eval(Container.DataItem, "ptsjtmmx_xh")%></td>
  <td id="s1" style="padding-right:5px;"><%# DataBinder.Eval(Container.DataItem, "ptsjtmmx_je")%></td>
  <td align="right"><input id="txtJE" type="text" t_value="" o_value="" style="width:200px; border:0px none white; height:25px; text-align:right;" onKeyPress="fkeyPress(this);" onkeyup="fkeyUp(this);" /></td>
  </tr>
  </ItemTemplate>
  </asp:Repeater>

  <tr align="center" style="height:25px;">
  <td style="width:50px; line-height:120%;">合计:</td>
  <td id="Sum1" style="width:150px; line-height:120%;"></td>
  <td id="Sum2" style="width:200px; line-height:120%;"></td>
  </tr>
  </table>

------解决方案--------------------------------------------------------
js DOM进行 啊

document.getElementById("设置个tableID").rows[i].cells[j]得到各个单元格,累加就可以了
------解决方案--------------------------------------------------------
    <script type="text/javascript">
        $(document).ready(function () {
            $("#tbid tr:last td:eq(0)").html("合计:" + ($("#tbid tr").length - 2));
            var val1 = 0;
            var val2 = 0;
            $("#tbid tr:gt(0)").not(":last").each(function () {
                val1 += parseInt($(this).find("td:eq(1)").html());
                val2 += parseInt($(this).find("td:eq(2)").html());
            })
            $("#tbid tr:last td:eq(1)").html(val1);
            $("#tbid tr:last td:eq(2)").html(val2);
        })
    </script>

    <div>
        <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse; width: 400px;" id="tbid">
            <tr align="center" style="height: 25px;">
                <th style="width: 50px; line-height: 120%;">序号</th>
                <th style="width: 150px; line-height: 120%;">样文</th>
                <th style="width: 200px; line-height: 120%;">录入列</th>
            </tr>
            <tr align="center" style="height: 25px;">
                <td style="width: 50px; line-height: 120%;">12</td>
                <td style="line-height: 120%;">1</td>
                <td style="line-height: 120%;">2</td>
            </tr>
            <tr align="center" style="height: 25px;">
                <td style="width: 50px; line-height: 120%;">12</td>
                <td style="line-height: 120%;">1</td>
                <td style="line-height: 120%;">2</td>
            </tr>
            <tr align="center" style="height: 25px;">
                <td style="width: 50px; line-height: 120%;">12</td>
                <td style="line-height: 120%;">1</td>
                <td style="line-height: 120%;">2</td>
            </tr>
            <tr align="center" style="height: 25px;">
                <td style="width: 50px; line-height: 120%;">合计:</td>
                <td id="Sum1" style="width: 150px; line-height: 120%;"></td>
                <td id="Sum2" style="width: 200px; line-height: 120%;"></td>
            </tr>
        </table>
    </div>

 

 

方式四

循环绑定的数据表累加

 

阅读更多
个人分类: asp.net
上一篇SQL Server 自增字段重置
下一篇IIS7.5 HTTP 错误 500.19 - Internal Server Error 问题的解决方案
想对作者说点什么? 我来说一句

repeater最牛最简洁统计法

2017年09月09日 44KB 下载

没有更多推荐了,返回首页

关闭
关闭