Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2014, 04:29 PM
Authorized User
 
Join Date: Mar 2014
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chapter 14 - Exercise 1 Solution

To get the 10 most recent reviews from the system, your query needs two important LINQ constructs:
first, it needs an Order By (orderby in C#) clause to order the list in descending order. It
then needs the Take method to take the first 10 reviews from that result set:

Code:
using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
{
var recentReviews = (from myReview in myEntities.Reviews
orderby myReview.CreateDateTime descending
select new { myReview.Title, myReview.Genre.Name }).Take(10);
GridView1.DataSource = recentReviews;
GridView1.DataBind();
}
What's the markup for this exercise. I'm using a repeater but I cannot get it to work to take the first 10 reviews?
 
Old March 31st, 2014, 06:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The exercise uses a GridView, so all you need is an <asp:GridView runat="sever" ID="GridView1" /> on your page.

For a Repeater, you can use something like this (written in this forum editor and thus untested):

Quote:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Literal text='<%# Eval("Title")' runat="server" /> in genre:
<asp:Literal text='<%# Eval("Name")' runat="server" />
</ItemTemplate>
</asp:Repeater>
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
southside123 (March 31st, 2014)
 
Old March 31st, 2014, 01:12 PM
Authorized User
 
Join Date: Mar 2014
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thanks. The problem is resolved.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4, Exercise 2 Solution malie22001 BOOK: Beginning Visual C# 2010 0 May 19th, 2012 11:43 PM
Chapter 14 Exercise 3 Solution pg 747 arodrigu12 BOOK: Beginning ASP.NET 4 : in C# and VB 2 April 21st, 2011 07:58 PM
Chapter 14 Exercise 3 and solution. UncleJeff BOOK: Beginning ASP.NET 4 : in C# and VB 2 March 14th, 2011 02:15 PM
Chapter 3 Exercise 4 Solution KurtBergman BOOK: Beginning Visual C# 2010 8 July 16th, 2010 08:13 PM
Solution to exercise 7, Chapter 2 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 28th, 2006 04:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.