Workshop


Quiz

1.

Name some of the ways in which the three list Web controls examined in this hour are similar to one another.

2.

Name some ways in which the list Web controls differ from one another.

3.

What is the name of the event that is raised when a list Web control's selected state is changed across postbacks?

4.

What properties must you set in order to have the RadioButtonList or CheckBoxList controls render their items laid out horizontally using multiple columns?

5.

The DropDownList, RadioButtonList, and CheckBoxList controls all have an AutoPostBack property. What happens when this property is set to true?

Answers

1.

All are composed of list items and contain a similar set of base propertiesItems, SelectedItem, SelectedValue, and so on. They all have a SelectedIndexChanged event that fires on postback if the selected state of the control has changed. Additionally, they all can have their list items specified in one of three ways: statically, through the ListItem Collection Editor dialog box; programmatically; and through a data source control.

2.

Each list Web control renders its list items differently. The DropDownList will always have one selected item, whereas the RadioButtonList can have zero or one, and the CheckBoxList can have zero to many selected items.

3.

SelectedIndexChanged.

4.

The RepeatColumns property specifies how many columns the RadioButtonList or CheckBoxList's items will use; the RepeatDirection property indicates whether the items are laid out vertically or horizontally.

5.

When AutoPostBack is set to true, any client-side change in the control's selection state causes a postback. For example, with a DropDownList whose AutoPostBack property is set to true, when the user chooses a new option from the list, the page automatically posts back and the DropDownList's SelectedIndexChanged event is fired.

Exercises

  1. Using the same techniques discussed in the "Filtering Results Using the DropDownList" section, create an ASP.NET page that uses a GridView to display the books from the Books table and a RadioButtonList of all of the authors to allow the user to filter the books displayed. (Be sure to set the RadioButtonList's AutoPostBack property to TRue.)

    Like in our earlier example, make sure that the RadioButtonList displays only unique author names. Also, because on the initial page load, the RadioButtonList will not have any item selected, you'll need to set a default value for the parameter you create in the GridView's SqlDataSource wizard. Set the default parameter value to a blank string. With this setting, when the page first loads, before a user selects an author from the list of radio buttons, the GridView should not be shown because there should be no authors with a blank string. Upon selecting a new author, the page will post back and the books that the selected author has written will be displayed.

    When testing this, be sure to edit the Books table so that there are at least two books written by the same author. Also, take a moment to set the GridView's EmptyDataText property to an applicable message. Recall that the value of this property is displayed when binding a GridView to a data source control that returns no records, as is the case with this exercise when the user first visits the page, before selecting an author.




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