Sum of DataTable columns total using Lambda Expression in Entity FrameWork in ASP.Net

Last Reply 8 months ago By dharmendr

Posted 8 months ago
 decimal total = dt.AsEnumerable().Sum(row => row.Field<decimal>("TotalAmount"));

when i try to add the total amount from grid view row then i'm faicing above error sir
Posted 8 months ago
fareed.fd7 says:
decimal total = dt.AsEnumerable().Sum(row => row.Field<decimal>("TotalAmount"));

 First make sure that TotalAmount field should be decimal in the datatable. If this is string then change with the below code.

decimal d = 0;
decimal total = dt.AsEnumerable().Where(row => decimal.TryParse(row["TotalAmount"].ToString(), out d)).Sum(row => d > 0 ? d : 0);


Posted 8 months ago

sir is it possible to give text and the value in same gridview cell

example: TotalAmount:<total amount>

Posted 8 months ago Modified on 8 months ago

Yes you can. For that you have to take template field something like below.

        <asp:Label ID="lblText" Text='<%# Eval("Text") %>' runat="server" />
        <asp:Label ID="lblValue" Text='<%# Eval("Value") %>' runat="server" />



Posted 8 months ago

but we are displaying result using footerrow cells, how can i use templatefield there



I agree, here is the link: