QA


Q&A

Q1:

From the home page the user is shown a GridView that lists all of the users in the system. Won't this list quickly become unwieldy when there are several dozen to hundreds of users?

A1:

Yes, the user interface for the home page was not designed with the idea of a site with hundreds of photo albums in mind. If you expect to have 50 or more accounts on your site, it would behoove you to create an easier means of listing the albums on the site. You might include a search feature, where a visitor could enter some text and all users whose UserName contains that text would be returned.

Another option would be to include additional bits of information in the table, such as how many pictures are in each user's album and when the last picture was added. This type of information would help visitors determine if a particular album was recently updated or had any pictures.

To include this additional information for each user, you will need to set the SqlDataSource control's SelectCommand to

SELECT UserId, UserName,        (SELECT COUNT(*) AS Expr1         FROM Pictures AS p         WHERE (UserId = u.UserId)) AS PictureCount,        (SELECT MAX(UploadedOn) AS Expr1         FROM Pictures AS p         WHERE (UserId = u.UserId)) AS LastUpdateOn FROM vw_aspnet_MembershipUsers AS u WHERE (IsApproved = @IsApproved) AND (IsLockedOut = @IsLockedOut) ORDER BY UserName 


This change can be made either declaratively, through the Source view, or via the SqlDataSource's wizard, by opting to specify the SQL query manually.

Q2:

I understand why, when adding a new category in the ManageCategories.aspx page, we need to programmatically supply the currently logged-on user's UserId value, but I'm at a bit of a loss as to why this information must be provided when updating the categories through the GridView. When we're editing a record, the UserId is already set, and we don't want to change this, so why does it need to be set at all? Can't we have the editing update just the Name column for a particular category and leave the UserId column out of it altogether?

A2:

When we created the SqlDataSource control in ManageCategories.aspx, we had it return the CategoryID, UserId, and Name column values. When we're configuring the SqlDataSource control to generate the INSERT, UPDATE, and DELETE statements, it automatically creates the UPDATE and INSERT statements to update and insert all nonprimary key columns. In this case, that's UserId and Name.

But, you're correct, the UserId value does not need to be updated when updating just the Name column, as through the GridView. You could manually adjust the SqlDataSource control's UpdateCommand and UpdateParameters properties to have the UPDATE statement update only the Name column; in that case, you wouldn't need to programmatically set the UserId value in the GridView's RowUpdating event handler.

If you wanted to go down this path, you would remove the reference to the UserId value and parameter, setting the SqlDataSource control's UpdateCommand property to

UPDATE [Categories] SET   [Name] = @Name WHERE [CategoryID] = @CategoryID 


You would also remove the <asp:Parameter Name="UserId" /> line from the SqlDataSource control's <UpdateParameters> section.




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