使用JQuery总计一个GridView列。 [英] Total a GridView column using JQuery.

查看:80
本文介绍了使用JQuery总计一个GridView列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到了如何在线总计一个gridview行的优秀示例。

需要帮助才能使其适应我的解决方案。



我猜测问题在于#GridView1 span [id * ='lblTotal']

,因为这是我从原始代码中做出的唯一真正的改变。



以下代码:



Found this excellent example of how to total a gridview row online.
Just need help in adapting it to my solution.

I'm guessing the problem lies with the line "#GridView1 span[id*='lblTotal']"
as this was the only real change I made from the original code.

Code below:

<script language="javascript" type="text/javascript">
     function calculate() {
     var Amount = 0;
     $("#GridView1 span[id*='lblTotal']").each(function (index) {
     //Check if number is not empty
     if ($.trim($(this).val()) != "")
     //Check if number is a valid integer
         if (!isNaN($(this).val()))
             Amount = Amount + parseFloat($(this).val());
 });
       $("#GridView1 span[id*='lblTotalAmount']").text(Amount);        }
  </script>





标记如下:





Mark up below:

 <asp:GridView ID="GridView1" runat="server"

AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" 

            DataSourceID="AccessDataSource1" 

            ShowFooter="True" style="margin-bottom: 0px">
            <Columns>
            <asp:TemplateField HeaderText="Devices And Services" Visible="True" HeaderStyle-HorizontalAlign="Left"  FooterText="Payable monthly in advance (excluding Agreement items):" ItemStyle-BackColor="#CCCCCC">
                    <ItemTemplate>
                        <asp:Label ID="lblItemDescription" runat="server" Width="382"

Text='<%# Eval("itemDescription") %>'></asp:Label>
                    </ItemTemplate>

<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Rate">
                    <ItemTemplate>
                        <asp:Label ID="lblRate" runat="server" width="50" ></asp:Label>
                       
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Number" ControlStyle-BackColor="#FFFFCC">
                    <ItemTemplate>
                        <asp:TextBox ID="txtBoxNumber" Width="100px"

runat="Server"  />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Total" ItemStyle-CssClass="total">
                    <ItemTemplate>                  
                        <asp:Label ID="lblTotal" runat="Server"  Width="106"  />
                    </ItemTemplate>
                    <FooterTemplate>
                          
                 <asp:Label ID="lblTotalAmount" runat="server"  />        
                
                    </FooterTemplate>
                </asp:TemplateField>
              
               
                  
                    
                
            </Columns>
            <FooterStyle Font-Bold="True" />
        </asp:GridView>





在我的解决方案中,我的lblTotal已计算通过Javascript



代码如下:





In my solution my lblTotal is calculated through Javascript

Code Below:

<script type="text/javascript">

    function multiply(Rate, number, total) {
        
        var grid = document.getElementById('GridView1');      
        var num = parseFloat(document.getElementById(number).value);
        var tot = document.getElementById(total);
      
        var totValue = parseFloat(((Rate * num)));
        var totValueRound = Math.round(totValue);
        var totValueRound = totValue;
        tot.innerHTML =  totValue.toFixed(2);
        calculate();
       
    }
<script/> 

推荐答案

#GridView1 span [id * ='lblTotal'])。each( function (index){
// 检查数字是否为空
if
("#GridView1 span[id*='lblTotal']").each(function (index) { //Check if number is not empty if (


.trim(


this )。val())!=
// < span class =code-comment>检查数字是否为有效整数
如果(!isNaN(
(this).val()) != "") //Check if number is a valid integer if (!isNaN(


这篇关于使用JQuery总计一个GridView列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆