Piush shukla
Piush shukla

Reputation: 165

Gridview how to Subtract two item

I have a grid view.In this i want balance= total paid leave-paid leave taken what shoul i do

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

Upvotes: 0

Views: 3573

Answers (2)

Ravi Gadag
Ravi Gadag

Reputation: 15861

you can try like this

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

Upvotes: 2

Thit Lwin Oo
Thit Lwin Oo

Reputation: 3438

Why don't you do that calculation in sql? That's better and easy to manage.

for eample

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

Upvotes: 1

Related Questions