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

Last Reply 29 days ago By dharmendr

Posted 29 days 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 29 days 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 29 days ago

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

example: TotalAmount:<total amount>


Posted 29 days ago Modified on 29 days ago

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

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

 

 


Posted 29 days ago

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

 

 


I agree, here is the link: http://e-iceblue.com/free-api