QA


Q&A

Q1:

In the "Displaying Hyperlinks with the HyperLinkField" section, we learned that the HyperLinkField's URL value can be constructed using multiple database values by setting the DataNavigateUrlFields property to a comma-delimited list of database column names. Does this also apply to the text value (DataTextUrlField)?

A1:

No, the HyperLinkField supports multiple column names only in its URL portion. The DataTextUrlField property can accept only one column name. Similarly, the ImageField's DataAlternateTextField and DataImageUrlField properties can be assigned only to a single column name.

Q2:

In the "Using Wildcards in a WHERE Filter Expression" section, we saw how to display all books where the title contained a search term entered by the user. Would it be possible to make a more general search engine, one that would return a book whose title, author, or genre matched the search term entered by the user?

A2:

Yes, this would be possible. You would need to add multiple WHERE clause conditions, using the same pattern for each. However, when you specify the SELECT clause through the Specify a Selected Statement screen of the SqlDataSource wizard, the WHERE clause filter expressions specified are joined by ANDs. That is, if you followed the steps outlined earlier in this hour and added three filter expressions to the Title, Author, and Genre columns using the LIKE operator with a parameter value based on the titleSearch TextBox, the resulting SELECT query would be

SELECT * FROM [Books] WHERE ([Title] LIKE '%' + @Title + '%') AND       ([Author] LIKE '%' + @Author + '%') AND       ([Genre] LIKE '%' + @Genre + '%') 


Note that the three conditions in the WHERE clause are joined by an AND. That means the only rows that will be returned will be those whose Title column value contains the user's search term and whose Author column value contains the user's search term and whose Genre column value contains the user's search term. What we want, though, is to have all books returned where any of those columns contain the search term.

To accomplish this, you'll have to craft the SELECT statement yourself through the SqlDataSource wizard's Define Custom Statements or Stored Procedures screen. (This screen was first discussed in Hour 14.)

Q3:

What if I want to display an image (or hyperlink), but I need more control over the way the image or hyperlink is rendered than the ImageField or HyperLinkField grants? For example, what if I want to have two images in the field, or I want some nonlinked text to appear after the hyperlink?

A3:

For simple links and images, the HyperLinkField and ImageField work wonderfully. However, if you need greater flexibility in the appearance of these fields, you'll need to use a TemplateField instead. You can simply convert the HyperLinkField or ImageField into a TemplateField and then customize the ItemTemplate as needed. If you add new Web controls, be sure to configure their data bindings as needed.




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