Can you use LINQ extension method statements in an ASP.NET data binding expression?

Can I use the LINQ extension method in an ASP.NET data binding expression?

Inside a GridView bound to the Customer collection, which in turn has a collection of phones associated with it, the following Eval expression fails:

<%# Eval("Phones.Single(p => p.PhoneTypeId == 2)") %> 

The error message I get is: "First (p => p" is not a valid indexed expression

Is it possible to use LINQ extension operations in a binding expression?

+4
source share
1 answer

No, it is not. Lambda expressions are an extended type of expression that is not supported by Asp.Net data binding expressions. Binding expressions are a much simpler language. They support property and field names (including indexer expressions).

http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx

+3
source

All Articles