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

Last Reply one year ago By dharmendr

Posted one year 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 one year 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 one year ago

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

example: TotalAmount:<total amount>

Posted one year ago Modified on one year 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 one year ago

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



I agree, here is the link: