Skip to Content
Beginning ASP.NET 3.5: In C# and VB
book

Beginning ASP.NET 3.5: In C# and VB

by Imar Spaanjaars
March 2008
Intermediate to advanced content levelIntermediate to advanced
766 pages
21h 15m
English
Wrox
Content preview from Beginning ASP.NET 3.5: In C# and VB

A.13. Chapter 13

A.13.1.

A.13.1.1.
A.13.1.1.1. 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 to use the Take method to take the first 10 reviews from that result set:

VB.NET

Dim recentReviews = (From myReview In myDataContext.Reviews _
                    Order By myReview.CreateDateTime Descending _
                    Select New With {myReview.Title, myReview.Genre.Name}).Take(10)

GridView1.DataSource = recentReviews
GridView1.DataBind()

C#

var recentReviews = (from myReview in myDataContext.Reviews
                    orderby myReview.CreateDateTime descending
                    select new
                    {
                      myReview.Title,
                      myReview.Genre.Name
                    }).Take(10);

GridView1.DataSource = recentReviews;
GridView1.DataBind();

This code also uses the New keyword (new in C#) to create a new, anonymous type that only contains the review's title and the genre's name.

A.13.1.1.2. Exercise 2 solution

The biggest benefit of the ListView control is that it combines the strengths of those other data controls. Just like the GridView control, the ListView control makes it easy to display data in a grid format that users can edit from within the grid. Additionally, the ListView control allows you to insert new records, behavior that is found in controls like DetailsView and FormView but not in GridView.

Finally, the ListView control gives you full control over the markup that gets sent to the browser, an important ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning ASP.NET 4: in C# and VB

Beginning ASP.NET 4: in C# and VB

Imar Spaanjaars
Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader

Publisher Resources

ISBN: 9780470187593Purchase book