Gridview如何减去两个项目

时间:2012-02-13 05:30:41

标签: c# asp.net gridview

我有一个网格视图。在此我想要余额=已支付的带薪休假总假期 我应该做什么

<asp:TemplateField HeaderText="Total Paid Leaves" SortExpression="Location_name">
    <EditItemTemplate>
        <asp:TextBox ID="txttotal_paid_leaves" runat="server" Text='<%# Eval("total_paid_leaves") %>'>
        </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
        <asp:TextBox ID="txtNewtotal_paid_leaves" runat="server"></asp:TextBox>
    </FooterTemplate>
    <ItemTemplate>
        <asp:Label ID="Label2" runat="server" Text='<%# Bind("total_paid_leaves") %>'>
        </asp:Label>
    </ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Paid Leaves taken">
    <EditItemTemplate>
        <asp:TextBox ID="txtpaid_leaves_taken" runat="server" Text='<%# Bind("paid_leaves_taken") %>'></asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
        <asp:TextBox ID="txtNewpaid_leaves_taken" runat="server">
        </asp:TextBox>
    </FooterTemplate>
    <ItemTemplate>
        <asp:Label ID="lblpaid_leaves_taken" runat="server" Text='<%# Bind("paid_leaves_taken") %>'>
        </asp:Label>
    </ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Balance">
    <ItemTemplate>

    ----Please guide me in this part----

    </ItemTemplate>
</asp:TemplateField>

2 个答案:

答案 0 :(得分:2)

你可以这样尝试

  <ItemTemplate>
    <asp:Label ID="Label3" runat="server" Text='<%#Convert.ToInt32(Eval("TotalLeave")) -Convert.ToInt32(Eval("LeaveTaken")) %>'></asp:Label>
    </ItemTemplate>

答案 1 :(得分:1)

为什么不在sql中进行计算?这更好,更容易管理。

for eample

SELECT TOTAL_LEAVE, LEAVE_TAKEN, (TOTAL_LEAVE - LEAVE_TAKEN) BALANCE
FROM TABLE
WHERE .......