Subtracting Value of two bonded fields

1.4k views Asked by At

i want to subtract values of two boundFields in gridview and show result in a template filed on run time .. Here is the code

<asp:BoundField ControlStyle-Width="5%" DataField="totalamount" HeaderText="Total" />
<asp:BoundField ControlStyle-Width="5%" DataField="paidamount" HeaderText="Paid" />
<asp:TemplateField HeaderText="Balance"> totalamount-paidamount</asp:TemplateField>

i want to do it in aspx file not code behind..

2

There are 2 answers

0
AddyProg On BEST ANSWER

Problem Solved :-)

<asp:TemplateField HeaderText="Balance" ControlStyle-Width="3%">    
            <ItemTemplate>
            <asp:Literal 
       ID="Literal4" 
       runat="server" 
       Text='<%# (Decimal.Parse(Eval("totalamount").ToString())-Decimal.Parse(Eval("paidamount").ToString())).ToString("N2") %>'>
    </asp:Literal> 
            </ItemTemplate>
            </asp:TemplateField>
2
Tim Schmelter On

Try this:

<asp:TemplateField HeaderText="Balance"> 
    <%# System.Convert.ToDecimal(Eval("totalamount")) - System.Convert.ToDecimal(Eval("paidamount")) %>
</asp:TemplateField>