How does LINQ know to display the title of a review??
Hi,
I'm currently in Chapter 14 "Linq and the ADO.Net Entity Framework" and am on the Try It out "Working with Queries and anonymous types".
The try out uses a repeater and a bulleted list to display a Genre and each review associated with that Genre using this C# / ASP.Net code
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Name") %>'></asp:Literal></h3>
<asp:BulletedList ID="ReviewList" runat="server" DataSource='<%# Eval("Reviews") %>'
DataTextField="Title" DisplayMode="Text">
</asp:BulletedList>
</ItemTemplate>
</asp:Repeater>
using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
{
var allGenres = from genre in myEntities.Genres
orderby genre.Name
select new {genre.Name, genre.Reviews};
Repeater1.DataSource = allGenres;
Repeater1.DataBind();
}
The bit in bold I don't understand, how does the bulleted list know to display the title of each review and not another column from the reviews table??
Thanks
Dale
Apologies, I've found the answer. Wasn't looking hard enough....
<asp:BulletedList ID="ReviewList" runat="server" DataSource='<%# Eval("Reviews") %>'
DataTextField="Title" DisplayMode="Text">
Nothing to see here.
Last edited by DCT1984; July 14th, 2011 at 11:33 AM..
Reason: Found the answer
|