Javascript在文本框上显示gridview列的总和。 [英] Javascript to show the gridview column sum on a textbox.

查看:94
本文介绍了Javascript在文本框上显示gridview列的总和。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我有一个Gridview。我在一个列中的文本框。我需要当我在gridview文本框中输入数字时,它会计算文本框的总和并显示另一个文本框。我的asp代码在这里: -





 < ;   asp:GridView     ID   =  GridOtherFee    runat   =  server    AutoGenerateColumns   =  false     CssClass   =  mGrid    DataSourceID   =  SqlOtherFee >  
< > ;


< asp:BoundField DataField = Abb HeaderText = FeeHead ReadOnly = True HeaderStyle-Width = 100px / >

< asp:TemplateField SortExpression = 金额 HeaderText = 金额 ItemStyle-Horizo​​ntalAlign = HeaderStyle-Horizo​​ntalAlign = HeaderStyle-Width = 150px >
< ItemTemplate >
< asp:TextBox ID = TxtRecd runat = server 宽度 = 100px AutoPostBack = < span class =code-keyword> true CssClass = aligntext > < / asp:TextBox >
< / ItemTemplate >
< / asp:TemplateField >

< /列 >

< / asp:GridView >



< br $>


< asp:TextBox ID =txtFeeRecdrunat =servername =aWidth =100 pxReadOnly =trueCssClass =aligntext>






当我输入数字时
在gridview txtrecd文本框中显示textfeereced textbox中的显示总和..

解决方案

在某些按钮单击或新行创建或任何您想要的事件上调用此方法



  private   void  GrandTotal()
{
float GTotal = 0f;
for int i = 0 ; i < GridView1.Rows.Count; i ++)
{
String total =(GridView1.Rows [i] .FindControl( lblTotal as Label).Text;
GTotal + = Convert.ToSingle(total);
}
txtTotal.text = GTotal.toString();
}





希望它有所帮助..


Sir, i have a Gridview. in which i take a textbox in a column. i need that when i enter numbers in gridview textbox then it calculate the sum of textbox and show one another textbox. my asp code is here:-


<asp:GridView ID="GridOtherFee" runat="server" AutoGenerateColumns="false" CssClass="mGrid" DataSourceID="SqlOtherFee">
      <Columns>


          <asp:BoundField DataField="Abb" HeaderText="FeeHead" ReadOnly="True"  HeaderStyle-Width="100px"/>

          <asp:TemplateField SortExpression="Amount" HeaderText=" Amount" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"  HeaderStyle-Width="150px">
              <ItemTemplate>
                  <asp:TextBox ID="TxtRecd"  runat="server" Width="100px" AutoPostBack="true" CssClass="aligntext"></asp:TextBox>
              </ItemTemplate>
          </asp:TemplateField>

      </Columns>

  </asp:GridView>




<asp:TextBox ID="txtFeeRecd" runat="server" name="a" Width="100px" ReadOnly="true" CssClass="aligntext" >



when i enter digits in gridview txtrecd textbox the sum of show in textfeereced textbox..

解决方案

Call this Method on some button click or on new row creation or whatever event you want to

private void GrandTotal()
    {
     float GTotal = 0f;
     for (int i = 0; i < GridView1.Rows.Count; i++)
     {
        String total = (GridView1.Rows[i].FindControl("lblTotal") as Label).Text;
        GTotal += Convert.ToSingle(total);
     }
     txtTotal.text=GTotal.toString();
    }



Hope it will help..


这篇关于Javascript在文本框上显示gridview列的总和。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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