03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Summary x 551<br />

model. Comb<strong>in</strong>ed with the new ListView <strong>and</strong> DataPager controls, the EntityDataSource enables<br />

you to create fully functional CRUD pages.<br />

Until now, the database-driven pages you have seen look quite dull. You haven’t applied a lot of styl<strong>in</strong>g,<br />

or provided any conditional formatt<strong>in</strong>g, where data is presented differently based on its values.<br />

You can do this through control styles <strong>and</strong> the many events of the data-bound <strong>and</strong> data source controls.<br />

The next chapter shows you how to make use of these styles <strong>and</strong> events.<br />

EXERCISES<br />

1. Imag<strong>in</strong>e you have a page <strong>in</strong> the Reviews folder called MostRecent.aspx. This page should show<br />

the 10 most recently added reviews. What would your LINQ query look like if you only wanted to<br />

show the review’s Title property <strong>and</strong> the name of the genre it belongs to? You should use the<br />

Take method to limit the result set to 10. If you’re hav<strong>in</strong>g trouble writ<strong>in</strong>g the code to get the last<br />

reviews, look at the section titled “First, FirstOrDefault, Last, <strong>and</strong> LastOrDefault,” which shows you<br />

how to get the last review <strong>in</strong> the database.<br />

2. What is the major benefit of the ListView control over other data controls like GridView <strong>and</strong><br />

Repeater?<br />

3. Currently the Default.aspx page from the PhotoAlbums folder just shows the thumbnails of the<br />

pictures. What would you need to do to display the full-size picture on its own page us<strong>in</strong>g a LINQ<br />

query?<br />

4. When you delete a picture from the ListView on the Photo Album page, only the database row is<br />

deleted, but the image on disk is left untouched. Make use of the static System.IO.File.Delete<br />

method to delete the item from disk. Choose an appropriate event of the EntityDataSource to<br />

h<strong>and</strong>le this <strong>and</strong> make use of the Entity property that is available on the e argument of the event.<br />

5. Currently, the AllByGenre.aspx page displays the title of the genre, regardless of whether it has<br />

any reviews attached to it. How can you hide genres that don’t have any reviews? Make use of the<br />

Count method on the Reviews collection to solve this question.<br />

You can f<strong>in</strong>d answers to these exercises <strong>in</strong> Appendix A.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!