Summary

In this chapter, we examined how to alter the data being displayed based on its value. On an ASP.NET Web page, this can be accomplished in two ways: providing a custom function that is called using the data-binding syntax and is passed the value of one or more DataSource fields; or by providing an event handler for the data Web control's ItemDataBound event.

With the custom functions in the data-binding syntax, the results of one or more fields of the current row in the DataSource can be examined to produce the output. Take, for example, an auction Web site like eBay. When a user searches on a term, the matching auctions are returned along with the time remaining in the auction. For auctions that have, say, less than one hour to go, we might want to display the remaining time in a red colored, bolded font. This can easily be accomplished using custom functions. Additionally, custom functions can be used to produce values that are computed from one or more DataSource fields, as was shown in Listing 11.3.

The data bound to each item in a data Web control can also be configured based upon its value by providing an event handler for the ItemDataBound event. Recall that the ItemDataBound event fires each time an item for a data Web control is bound to the current item of the DataSource. Customizing the output in the ItemDataBound event allows for more flexibility, because one can alter the contents of the data Web control's entire item, as opposed to just a particular DataSource field value. For example, in Listing 11.6, we saw how to highlight the item for each book whose price was greater than $20.00. Highlighting an item in this way is not possible through the custom function method.

Throughout this book, we have seen numerous examples showing how to explicitly display a DataSource field in the column of a DataGrid by using a BoundColumn or TemplateColumn. We have also examined a number of other DataGrid column types, such as the EditCommandColumn, HyperLinkColumn, and ButtonColumn. In the next chapter, "A More Advanced Examination of Using Templates," we will see how to programmatically create our own custom DataGrid columns!



ASP. NET Data Web Controls Kick Start
ASP.NET Data Web Controls Kick Start
ISBN: 0672325012
EAN: 2147483647
Year: 2002
Pages: 111

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