js 操作GridView

 

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
      <script type="text/javascript" language="javascript">
        function caculate()
        {
            var row = document.all.GrdOrderInfo.rows.length-1;
            var flag =document.all.GrdOrderInfo.rows(row).cells(0).innerText
            if(flag.trim() != "first")
            {
                row = document.all.GrdOrderInfo.rows.length-2;
            }
            var sum = 0.0;
            var sumlr = 0.0;
            for( i=1;i<row;i++)
            {
                 var cb=document.all.GrdOrderInfo.rows(i).cells(0).children(0);
                 if(cb.checked)
                 {
                      var pmoney=document.all.GrdOrderInfo.rows(i).cells(16).innerText;
                      var money=document.all.GrdOrderInfo.rows(i).cells(22).children(0).value;
                      try
                      {
                        var lirui=Number(pmoney) - Number(money);
                        document.all.GrdOrderInfo.rows(i).cells(21).innerText = lirui;
                        sumlr = Number(sumlr) + Number(lirui);
                        sum = Number(sum) + Number(money);
                      }
                      catch(ex)
                      {
                         alert(ex);
                      }
                 }
            }
            document.all.GrdOrderInfo.rows(row).cells(21).innerText = sumlr;
            document.all.GrdOrderInfo.rows(row).cells(22).innerText = sum;
       
        }
   
    String.prototype.trim = function()
    {
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align:center">
        <table border="0" cellpadding="0" cellspacing="0" class="mk" runat="server" id="mainTable">
        <tr>
            <td align="center">
                 <asp:GridView ID="GrdOrderInfo" runat="server" AutoGenerateColumns="False" BackColor="White"
                        BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="p_id"
                        EmptyDataText="没有任何订单信息" GridLines="Horizontal" Width="100%" AllowPaging="True" OnPageIndexChanging="GrdOrderInfo_PageIndexChanging"
                        OnRowDataBound="GrdOrderInfo_RowDataBound" PageSize="20" ShowFooter="True">
                        <FooterStyle CssClass="GridViewFooterStyle" />
                        <RowStyle CssClass="GridViewRowStyle" Height="24px" />
                        <Columns>
                            <asp:TemplateField HeaderText="选择">
                                <ItemTemplate>
                                    <asp:CheckBox ID="chbSelect" runat="server" onclick="caculate();" />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="lblsum" runat="server" Text="first" Width="99%" style="display:none"></asp:Label>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <%--<asp:BoundField HeaderText="出票日期" DataField="出票日期" />--%>

                            <asp:TemplateField HeaderText="出票日期">
                                <ItemTemplate>
                                    <asp:Label ID="lblTicketDate" runat="server" Width="99%" Text='<%#Eval("出票日期") %>'></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="lblsum" runat="server" Text="合计" Width="99%"></asp:Label>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="代理商" DataField="代理商"/>
                            <asp:BoundField HeaderText="分部名称" DataField="分部名称"/>
                            <asp:BoundField HeaderText="单位名称" DataField="单位名称"/>
                            <asp:BoundField HeaderText="单位部门" DataField="单位部门"/>
                            <asp:BoundField HeaderText="票号" DataField="票号"/>
                            <asp:BoundField HeaderText="旅客姓名" DataField="旅客姓名"/>
                            <asp:BoundField HeaderText="航程" DataField="航程"/>
                            <asp:BoundField HeaderText="航司" DataField="航司"/>
                            <asp:BoundField HeaderText="航班号" DataField="航班号"/>
                            <asp:BoundField HeaderText="舱位" DataField="舱位"/>
                            <asp:BoundField HeaderText="乘机日期" DataField="乘机日期"/>
                            <asp:BoundField HeaderText="票面价" DataField="票价"/>
                            <asp:BoundField HeaderText="税费" DataField="税"/>
                            <asp:BoundField HeaderText="退票费" DataField="退票费"/>
                            <asp:BoundField HeaderText="票款" DataField="合计"/>
                            <asp:BoundField HeaderText="政策值(3+X)" DataField="政策值"/>
                            <asp:BoundField HeaderText="应收利润" DataField="应收利润"/>
                            <asp:BoundField HeaderText="应付金额" DataField="应付金额"/>
                            <asp:BoundField HeaderText="实际(3+X)值" DataField="政策值"/>
                            <asp:TemplateField HeaderText="实际利润">
                                <ItemTemplate>
                                    <asp:Label ID="lblFactlirui" runat="server" Width="99%" Text='<%#Eval("应收利润") %>'></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="lblsumlirui" runat="server" Text="0" Width="100%"></asp:Label>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="实付金额">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtFactMoney" runat="server" Width="60" Text='<%#Eval("应付金额") %>'
                                    onkeypress="if ((event.keyCode != 46 && event.keyCode < 48) || event.keyCode >57) event.returnValue = false;"
                                    onchange="caculate();"
                                    ></asp:TextBox>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="lblsumMoney" runat="server" Text="0" Width="100%"></asp:Label>
                                </FooterTemplate>
                            </asp:TemplateField>                              
                        </Columns>
                        <PagerStyle BackColor="#E7E7FF" CssClass="GridViewPagerStyle" ForeColor="#4A3C8C"
                            HorizontalAlign="Right" />
                        <SelectedRowStyle CssClass="GridViewSelectedRowStyle" Font-Bold="True" />
                        <HeaderStyle CssClass="GridViewHeaderStyle" Font-Bold="True" />
                        <AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" />
                        <EmptyDataRowStyle ForeColor="Red" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
        </div>
    </form>
</body>
</html>

posted @ 2008-12-30 16:22    阅读(940)  评论(0编辑  收藏  举报