views:

213

answers:

1

Is it possible to use a LINQ extension method within an ASP.NET databinding expression?

Within a GridView that is bound to a Customer collection which in-turn has a related Phones collection the following Eval expression fails:

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

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

Is this possible to use the LINQ extension method operations within a binding expression?

+2  A: 

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

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

JaredPar