Question

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..

Was it helpful?

Solution 2

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>

OTHER TIPS

Try this:

<asp:TemplateField HeaderText="Balance"> 
    <%# System.Convert.ToDecimal(Eval("totalamount")) - System.Convert.ToDecimal(Eval("paidamount")) %>
</asp:TemplateField>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top