Summary

In this chapter we started by examining how to add ButtonColumns to the DataGrid Web control. We noted that these ButtonColumns can be rendered as hyperlinks or traditional HTML buttons. When a ButtonColumn button or hyperlink is clicked, the DataGrid's ItemCommand event is fired; to have some action associated with the clicking of a ButtonColumn, we need to provide an event handler for the ItemCommand event.

We also looked at using HyperLinkColumns to generate a hyperlink in each row of the DataGrid that ushers the user immediately to a specified Web page. We saw how the DataTextField, DataTextFormatString, DataNavigateUrlField, and DataNavigateUrlFormatString properties can be used to have the text and URL portions of the resulting hyperlink contain data from the particular DataGrid row on which they appeared.

Unfortunately, these properties are somewhat limiting in that they only allow for one DataSource field to be tied to the text and URL portions of the hyperlink. To overcome this limitation, we examined three different methods: using a ButtonColumn, using a TemplateColumn, and programmatically altering the Text and NavigateUrl properties of the HyperLinkColumn in the DataGrid's ItemDataBound event handler.

The main difference between ButtonColumns and HyperLinkColumns is that ButtonColumns, when clicked, result in a postback to the ASP.NET Web page as well as the firing of the DataGrid's ItemCommand event; HyperLinkColumns, on the other hand, immediately direct the user to the specified Web page, without performing a postback.

In the next chapter we'll look at how to use the standard ASP.NET Button and LinkButton controls within templates. When these buttons are clicked by the user, the data Web control's ItemCommand event is fired, which can be caught and handled by a server-side event handler. This approach not only allows both DataLists and Repeaters to utilize buttons, but also provides more flexibility than the DataGrid's ButtonColumn class.



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