Repeater结合JQ,对表格分行分列求和

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmFormBudget.aspx.cs" Inherits="DirBudget_frmFormBudget" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <script src="../Include/Common.js" type="text/javascript"></script>
    <script src="../Include/jquery-1.3.2.js" type="text/javascript"></script>
    <script src="../Include/jquery-1.2.3-intellisense.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $(".no").each(function () {
                var p = $(this);
                p.blur(function () {
                    checkFloat(this);
                    if ($(this).val() == '')
                        return;
                    var name = $(this).attr("id");
                    var ind = name.lastIndexOf("_") + 1;
                    name = name.substring(ind);
                    var PID = GetValue($(this), "tdParentID");
                    GetRowSum($(this))
                    GetColSum(PID, name);
                    GetColSum(PID, "Total");
                })
            });

            function GetColSum(PID, Name) {
                if (PID == "0" || PID == "")
                    return;
                var sum = 0;
                var YSID = "";
                //得到具有相同父ID的值,求和
                $("input[id$='" + Name + "']").each(function () {
                    if ($(this).val() != '') {
                        var v = GetValue($(this), "tdParentID");
                        if (PID == v)
                            sum += parseInt($(this).val());
                    }
                });
                //给ID为PID的控件赋值
                $("input[id$='" + Name + "']").each(function () {
                    var v = GetValue($(this), "tdYSID");
                    if (PID == v)//
                    {
                        //获取当前控件的父ID,用以递归
                        YSID = GetValue($(this), "tdParentID");
                        $(this).val(sum);
                    }
                });
                //递归求和
                GetColSum(YSID, Name);

            }
            //textbox控件句柄
            function GetRowSum(e) {
                var sum = parseInt(GetValue(e, "tdShiJv"))
                + parseInt(GetValue(e, "tdDongBu"))
                + parseInt(GetValue(e, "tdXiBu"))
                + parseInt(GetValue(e, "tdXiangZhou"))
                + parseInt(GetValue(e, "tdDiFang"))
                + parseInt(GetValue(e, "tdDouMen"))
                + parseInt(GetValue(e, "tdJinWan"));
                $(e).parent().parent().children("#tdTotal").children("input:first").val(sum);
            }

            function GetValue(e, tdName) {
                var re = $(e).parent().parent().children("#" + tdName + "").children("input:first").val();
                if (re != '') {
                    return re;
                }
                return 0;
            }



        });
    </script>
   
    <style type="text/css">
        .no
        {
            }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <table width="98%" border="0" align="center">
        <tr>
            <td align="center" class="FormTitle">
                <asp:Label ID="lblTitle" runat="server" Text="珠海市公路局编制年度预算表" />
            </td>
        </tr>
        <tr>
            <td>
                <table cellspacing="2" width="100%" border="0">
                    <tr style="height: 25px;">
                        <td align="right" width="25%">
                            <b>日期:  <asp:Label ID="conCurDate" runat="server"></asp:Label></b>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <table class="dgTbl" cellspacing="0" cellpadding="1" rules="all" border="1" width="100%"
                            align="center">
                    <tr>
                        <td class="rpF" width="15%" align="right">
                            <font color="red">*</font>请选择文件:

                        </td>
                        <td width="20%">
                            <input class="input_text" id="UpFile" type="file" size="25" name="UpFile" runat="server" />
                        </td>
                        <td class="rpF" align="right"  width="15%">
                            <font color="red">*</font>表头所在行:

                        </td>
                        <td width="10%">
                            <asp:TextBox class="input_text" ID="tbRowNum" runat="server" size="25" οnblur="checkInt(this)">3</asp:TextBox>
                        </td>
                        <td class="rpF" align="right"  width="15%">
                            <font color="red">*</font>工作簿名称:
                        </td>
                        <td width="15%">
                            <asp:TextBox class="input_text" ID="txtwBook" runat="server" size="25">总表</asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="6" align="center">
                            <asp:Button ID="btnImport" runat="server" CssClass="input_btn" Text="导   入" OnClick="btnImport_Click"
                                OnClientClick="return CheckForm();"></asp:Button>
                
                            <asp:Button ID="Button1" runat="server" Text="Button" CssClass="input_btn" 
                                οnclick="Button1_Click"/>
                
                        </td>
                    </tr>
                    <tr>
                        <td colspan="6" align="center">
                        <table class="dgTbl" cellspacing="0" cellpadding="1" rules="all" border="1" width="100%">
                            <tr class="rpH">
                                <td width="5%">序号</td>
                                <td width="20%">项目/单位</td>                
                                <td width="5%">合计</td>
                                <td width="5%">市局</td>
                                <td width="5%">东部管理处</td>
                                <td width="5%">西部管理处</td>
                                <td width="5%">香洲公路</br>养护中心</td>
                                <td width="5%">地方公路</br>养护中心</td>
                                <td width="5%">斗门公路</br>养护中心</td>
                                <td width="5%">金湾公路</br>养护中心</td>
                                <td width="35%">项目说明</td>
                            </tr>
                            <asp:Repeater runat="server" ID="rpList"><ItemTemplate>
                            <tr class="rpI">
                                <td style="display:none" id="tdYSID"><asp:TextBox ID="YSID" runat="server" Text='<%#Eval("YSID")%>' Width="95%"></asp:TextBox></td>
                                <td style="display:none" id="tdParentID"><asp:TextBox ID="ParentID" runat="server" Text='<%#Eval("ParentID")%>' Width="95%"></asp:TextBox></td>
                                <td><%#Container.ItemIndex+1 %></td>
                                <td id="tdProjectName"><asp:TextBox ID="ProjectName" runat="server" Text='<%#Eval("ProjectName")%>' Width="95%" ></asp:TextBox></td>
                                <td id="tdTotal"><asp:TextBox ID="Total" runat="server" Text='<%#Eval("Total") %>' Width="60px" CssClass="no"></asp:TextBox>
                                 <asp:TextBox runat="server" Width="30px" ReadOnly="true" BorderWidth="0"></asp:TextBox></td>
                                <td id="tdShiJv"><asp:TextBox ID="ShiJv" runat="server" Text='<%#Eval("ShiJv") %>' Width="60px" CssClass="no"></asp:TextBox>
                                 <asp:TextBox ID="TextBox1" runat="server" Width="30px" ReadOnly="true" BorderWidth="0"></asp:TextBox></td>
                                <td id="tdDongBu"><asp:TextBox ID="DongBu" runat="server" Text='<%#Eval("DongBu") %>' Width="60px" CssClass="no"></asp:TextBox>
                                 <asp:TextBox ID="TextBox2" runat="server" Width="30px" ReadOnly="true" BorderWidth="0"></asp:TextBox></td>
                                <td id="tdXiBu"><asp:TextBox ID="XiBu" runat="server" Text='<%#Eval("XiBu") %>' Width="60px" CssClass="no"></asp:TextBox>
                                <asp:TextBox ID="TextBox3" runat="server" Width="30px" ReadOnly="true" BorderWidth="0"></asp:TextBox></td>
                                <td id="tdXiangZhou"><asp:TextBox ID="XiangZhou" runat="server" Text='<%#Eval("XiangZhou") %>' Width="60px" CssClass="no"></asp:TextBox>
                                 <asp:TextBox ID="TextBox4" runat="server" Width="30px" ReadOnly="true" BorderWidth="0"></asp:TextBox></td>
                                <td id="tdDiFang"><asp:TextBox ID="DiFang" runat="server" Text='<%#Eval("DiFang") %>' Width="60px" CssClass="no"></asp:TextBox>
                                 <asp:TextBox ID="TextBox5" runat="server" Width="30px" ReadOnly="true" BorderWidth="0"></asp:TextBox></td>
                                <td id="tdDouMen"><asp:TextBox ID="DouMen" runat="server" Text='<%#Eval("DouMen") %>' Width="60px" CssClass="no"></asp:TextBox> 
                                <asp:TextBox ID="TextBox6" runat="server" Width="30px" ReadOnly="true" BorderWidth="0"></asp:TextBox></td>
                                <td id="tdJinWan"><asp:TextBox ID="JinWan" runat="server" Text='<%#Eval("JinWan") %>' Width="60px" CssClass="no"></asp:TextBox>
                                 <asp:TextBox ID="TextBox7" runat="server" Width="30px" ReadOnly="true" BorderWidth="0"></asp:TextBox></td>
                                <td id="tdDescription"><asp:TextBox ID="Description" runat="server" Text='<%#Eval("Description") %>' TextMode="MultiLine" Width="100%"></asp:TextBox></td>
                            </tr>
                            </ItemTemplate></asp:Repeater>
        
                        </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
       
    </table>
    </form>
</body>
</html>

发布了66 篇原创文章 · 获赞 2 · 访问量 6万+
展开阅读全文

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

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览