Performing Calculation In Gridview itemtemplate
<p>I want to perform calculation in a <code>GridView</code>: </p>

<pre><code>NetAmount = (ServiceAmount * Quantity) * Discount
</code></pre>

<p>I had written code in <code>RowDataBound</code> but it's not working. Can someone help me solve this problem? I would appreciate if some one share their knowledge.</p>

<p>my Aspx code:</p>

<pre><code>&lt;asp:GridView ID="GridView1" runat="server" Height="156px" Width="618px"
    AutoGenerateColumns="False" BorderWidth="1px" 
    HorizontalAlign="Justify" onrowdatabound="GridView1_RowDataBound" 
    BackColor="LightGoldenrodYellow" BorderColor="Tan" CellPadding="2" 
    ForeColor="Black" GridLines="None" onrowcommand="GridView1_RowCommand"&gt; 

    &lt;FooterStyle BackColor="Tan" /&gt;
    &lt;PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" /&gt;
        &lt;SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" /&gt;
        &lt;HeaderStyle BackColor="#FFFFC4" Font-Bold="True" ForeColor="#BF6000"/&gt;
        &lt;Columns&gt;
            &lt;!-- snip --&gt;
            &lt;asp:TemplateField HeaderText="Net Amt"&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:TextBox ID="TxtNetAmt" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" runat="server" Width="55px"&gt;&lt;/asp:TextBox&gt;
                &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
        &lt;/Columns&gt;
    &lt;AlternatingRowStyle BackColor="PaleGoldenrod" /&gt;
&lt;/asp:GridView&gt;


&lt;script type="text/javascript"&gt;
    function CalcSercode(ServiceAmount,Quantity, Discount,NetAmount)
    {
        var Quantity=parseFloat(document.getElementById(Quantity).value);
        var Discount= parseFloat(document.getElementById(Discount).value);
        var ServiceAmount=document.getElementById(ServiceAmount);
        var SerAmountValue = parseFloat((ServiceAmount * Quantity)-((ServiceAmount  *Quantity)*Discount/100));
        //var SellPriceValueRound = Math.round(SellPriceValue,4);
        var SerAmountValueRound = SerAmountValue;
        ServiceAmount.innerHTML= SerAmountValueRound ;
    }
&lt;/script&gt;
</code></pre>

<hr>

<p>My cs code :</p>

<pre><code>//TextBox TxtServiceCode =  GridView1.Controls[0].Controls[0].FindControl("TxtServiceCode") as TextBox;
//DataSet dss = new DataSet();
//SqlConnection MyConnection = new SqlConnection("server=prog; database=mydatabase;UID=sa;PWD=naco123;");
//SqlCommand sqlcmd = new SqlCommand("select * from [ServiceCode]",  MyConnection);
//SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
//DataSet ds = new DataSet();
//adp.Fill(ds);
//GridView1.DataSource = ds.Tables[0];
//GridView1.DataBind();
</code></pre>
