减去两个保税区的价值

时间:2014-01-08 10:45:19

标签: asp.net gridview templatefield

我想在gridview中减去两个boundField的值,并在运行时提交的模板中显示结果。 这是代码

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

我想在aspx文件中执行此操作而不是代码...

2 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:0)

解决问题: - )

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