0

我有一个网格视图

 <asp:gridview ID="Gridview1" runat="server" ShowFooter="true" CssClass="vutblrow" TabIndex="3" HeaderStyle-CssClass="vutblhdr" CellPadding="4" ForeColor="#333333" GridLines="None"  Width="25%" PagerStyle-Mode="NumericPages"


            AutoGenerateColumns="false" onrowcreated="Gridview1_RowCreated" Height="16px">
              <PagerStyle CssClass="pgr"  Height="25px" BorderStyle="Solid" />
            <Columns>
            <asp:BoundField DataField="RowNumber" HeaderText="Serial Number" />
            <asp:TemplateField HeaderText="Air/Bus/Train Fare">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" CssClass="txtBoxNormalmedium" ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="City To">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" CssClass="txtBoxNormalmedium" ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="City From">
                <ItemTemplate>
                     <asp:TextBox ID="TextBox3" runat="server" CssClass="txtBoxNormalmedium"></asp:TextBox>
                </ItemTemplate>
                <FooterStyle HorizontalAlign="Right" />
                <FooterTemplate>
                 <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row"
                        onclick="ButtonAdd_Click" CssClass="btnNormalAdd" />
                </FooterTemplate>
            </asp:TemplateField>
                 <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" CssClass="lnkbut">Remove</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>
        </asp:gridview>

 <asp:Label ID="lblgpf14" runat="server" CssClass="lblText " Text="Total Air Fare"></asp:Label>      
 <asp:TextBox ID="txt" runat="server" CssClass="txtBoxNormalmedium" Enabled="False" onkeyup="Calculate();"></asp:TextBox>

当用户输入航空/巴士/火车票价时,该值应显示在文本框“txt”中(使用 javacript 中的 onkeyup)此文本框位于 gridview 之外。当用户单击添加新行并输入火车票价时总值必须显示在“txt”中。我真的不知道如何为此编写javascript。有人可以帮我吗?

4

1 回答 1

0

绑定用户输入值的事件(根据您的问题在两个地方)说

<asp:TextBox ID="texboxid" onkeyup="showCal(this)" />

你的js脚本

function showCal(obj){

  var val=document.getElementById(obj.id).value;


      if(val!='' && !isNaN(val) ){
         var prvVal=document.getElementById('txt').value;
         prvVal= (!isNaN(prvVal))?prvVal:0;
        document.getElementById('txt').value = parseInt(prvVal)+parseInt(val);
      }else{
         alert("The value you have entered is either empty or not a number.")
      }
}
于 2013-10-30T09:33:05.610 回答