使用JavaScript错误在网格内将两个文本相乘 [英] Multiply two text inside grid using Javascript ERROR

查看:58
本文介绍了使用JavaScript错误在网格内将两个文本相乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的网格中有三个文本框...我需要将前两个文本值相乘并将其返回到第三个文本框.

我的代码...



i have three textbox inside my grid...I need to multiply first two text values and return it to third textbox.

My code...

protected void Grid_Purchase_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox txtqty = e.Row.FindControl("txt_grd_qty") as TextBox;
            TextBox txtprice = e.Row.FindControl("txt_grd_piece_amt") as TextBox;
            TextBox txtAmount = e.Row.FindControl("txt_grd_amt") as TextBox;
            txtqty.Attributes["onKeyup"] = "javascript: return GetTotal('" + Convert.ToInt32(txtqty.Text) + "','" + Convert.ToInt32(txtprice.Text) + "','" + Convert.ToInt32(txtAmount.ClientID) + "')";//Here i got the error as input string is not in corect format
            txtprice.Attributes["onKeyup"] = "javascript: return GetTotal('" + Convert.ToInt32(txtqty.Text) + "','" + Convert.ToInt32(txtprice.Text) + "','" + Convert.ToInt32(txtAmount.ClientID) + "')";
           
        }
    }




我的javascript ....




My javascript....

<script type="text/javascript">

 function GetTotal(Qty, Rate, txt3)
 {
document.getElementById(txt3).value=Qty*Rate;
}
 </script>




我的设计代码...




My design code...

<asp:TemplateField HeaderText="Quantity">
                  <ItemTemplate>
                      <asp:TextBox ID="txt_grd_qty" Width="75px" runat="server"></asp:TextBox>
                  </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                <FooterTemplate>
                    <asp:TextBox ID="Foot_Txt4" runat="server" Width="75px"></asp:TextBox>
                </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Piece/Amt">
                  <ItemTemplate>
                      <asp:TextBox ID="txt_grd_piece_amt" Width="75px" runat="server" AutoPostBack="true" ></asp:TextBox>
                  </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                <FooterTemplate>
                    <asp:TextBox ID="Foot_Txt5" runat="server" Width="75px"></asp:TextBox>
                </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Amount">
                  <ItemTemplate>
                      <asp:TextBox ID="txt_grd_amt" runat="server" Width="75px" Enabled="false" ></asp:TextBox>
                  </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                <FooterTemplate>
                    <asp:TextBox ID="Foot_Txt6" runat="server" Width="75px"></asp:TextBox>
                </FooterTemplate>
                  </asp:TemplateField>

推荐答案

删除
Convert.ToInt32(txtAmount.ClientID)


这篇关于使用JavaScript错误在网格内将两个文本相乘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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