网格视图如何减去两项

本文关键字:两项 视图 何减去 网格 | 更新日期: 2023-09-27 18:24:10

我有一个网格视图。在这方面,我想要余额=带薪休假总数我该怎么做

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

网格视图如何减去两项

你可以试试这个

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

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

例如

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