How to use check box lists and radio button listsEarlier in this chapter, you learned how to use radio buttons and check boxes. But ASP.NET also provides check box lists and radio button lists that you can use to create lists of check boxes and radio buttons. As figure 6-13 shows, these controls work like the other list controls.In the aspx code for the check box list and radio button list in this figure, you can see the Listltem objects. You can use the Collection Editor to add these objects after you add a check box list or radio button list to a form. Like check boxes and radio buttons, more than one item can be checked in a check box list, but only one item can be selected in a radio button list. You can also use the SelectedValue property to get or set the value of the selected item in a radio button list, but note in the first example that this code is simpler for a radio button list than it is when you’re using radio buttons in a group.Like a list box, you can select more than one item in a check box list. Because of that, you’ll usually determine whether an item in the list is selected by using the Selected property of the item. This is illustrated in the second example in this figure. Here, the Items property of a check box list is used to get the item at index 0. Then, the Selected property of that item is used to determine if the item is selected. Notice here that you can’t refer to individual check boxes by name when you use a check box list.To set the layout of the items in a radio button or check box list, you use the attributes shown in this figure. The RepeatLayout attribute determines how ASP.NET aligns the buttons or check boxes in a list. In most cases, you’ll use a table, which is the default. Then, ASP.NET generates the input and label elements for the boxes or buttons within the rows and columns of the table, which should limit the need for CSS formatting.Similarly, the RepeatDirection attribute determines whether the controls are listed horizontally or vertically. And the RepeatColumns attribute specifies the number of columns in the radio button or check box list. If you experiment with these, you should get the boxes and buttons aligned the way you want them. And this can be much easier than using CSS to align check boxes and radio buttons that aren’t in lists
đang được dịch, vui lòng đợi..
