Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

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

My code...

C#
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) + "')";
           
        }
    }



My javascript....

XML
<script type="text/javascript">

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



My design code...

XML
<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>
Posted
Updated 5-Jul-11 8:24am
v2

1 solution

Remove the conversion of
C++
Convert.ToInt32(txtAmount.ClientID)
 
Share this answer
 
Comments
J.Karthick 5-Jul-11 11:20am    
yeah...its works fine now...Thanks

But while Postback that multiplied value got Cleared...May i know how to toggle it?
hitesh_tech 5-Jul-11 11:51am    
For that you will have to use viewstate to maintain the value of control you want

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900