QA


Q&A

Q1:

Currently, the photo album application allows only JPEG images to be uploaded. How can I extend the application to allow for other image file formats to be uploaded?

A1:

When an image is uploaded to a user's album, the picture's filename is saved using the PictureID value of the newly inserted record into the Pictures table. Although the PictureID value can be used to uniquely identify each picture, it cannot express the image's file extension.jpg, .gif, .bmp, and so on.

You can resolve this problem in two ways: Either limit the application to allowing only one file extension or add an additional field to the Pictures table that captures the uploaded image's extension. Our application uses the former approach, but you can enhance the system to use the latter one by augmenting the Pictures table to include an ImageExtension column. When the user uploads an image, you would programmatically set the ImageExtension property to the extension of the uploaded file in the dvPictureInsert_ItemInserting event handler.

This approach introduces a new challenge when viewing the image files through an ImageField in the GridViews or DetailsViews, which is why I opted to restrict files of type JPEG for this application. Recall that the ImageField's image source URL can be configured via the DataImageFieldUrl and DataImageFieldFormatString properties, but only one databound column can be specified in the DataImageFieldUrl property, whereas now we need twoone for PictureID and one for ImageExtension.

There are a couple of ways to accomplish this. You can add a computed column to the Pictures table that will automatically concatenate the PictureID and ImageExtension columns, or you can customize the SELECT statement used by the SqlDataSource control to concatenate the two column values into one. Either way, these are slightly more advanced topics. If you are interested in exploring these options, consider asking for assistance on the ASP.NET Forums.

Q2:

In the PhotoDetails.aspx page, I'd like to include a back link to the user's photo album. How can I accomplish this?

A2:

When the user clicks the View link from PhotoAlbum.aspx, he is taken to PhotoDetails.aspx, where he is shown the particular picture and its comments. Currently, there is no way to return to the particular user's photo album other than hitting the browser's Back button.

The challenge in providing a back link in PhotoDetails.aspx is that we must know the UserId of the user whose picture we are viewing. That is, when viewing Blue Hills (see Figure 24.20), we have to know that this is Jisun's picture, because to return to Jisun's album, we need to go back to PhotoAlbum.aspx?ID=Jisun'sUserID.

Because PhotoDetails.aspx is passed the PictureID of the photo to display, and because the Pictures table has a UserId associated with each picture, we could include the UserId column in the SqlDataSource. Then, in the DetailsView, we would add a HyperLinkField whose Text property was set to "Back to the Photo Album" and whose DataNavigateUrlFields and DataNavigateUrlFormatString properties were set to UserId and PhotoAlbum.aspx?ID={0}, respectively. This would add a back link to the DetailsView that would return the user to the correct photo album.

Q3:

In the comments displayed in the PhotoDetails.aspx page, the name of the person who made the comment is not shown. How can I add this?

A3:

The Comments table doesn't contain the name of the person who made the comment; instead, it contains just the person's UserId. To retrieve the person's username, we would have to perform a join between the Comments table and the aspnet_Users table, which is the table that contains the username for each user in the system.

A join is a type of SQL query that retrieves records from two or more tables, joining the records based on relationships among the tables involved. Join syntax can be a bit tricky, but Visual Web Developer makes it easy when you are specifying a query manually in the SqlDataSource control wizard. Simply add the tables that you want to involve in the join and then check the columns to return from the tables. Visual Web Developer will automatically inject the correct join syntax.

If you decide to make this enhancement, do so with a new SqlDataSource control. That is, don't use the existing commentsDataSource SqlDataSource control in PhotoDetail.aspx because the DetailsView uses this datasource control for adding new comments. Instead, create a new SqlDataSource, configure it to join together the appropriate records from the Comments and aspnet_Users tables, and then bind this control to the GridView of comments.




Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net