Author: Ma Jinhu from: yesky
The Checkbox Selection component is a regular component in a program. This component is used in programming, generally not only one, often appears in the form of multiple such components. In the ASP.NET page, if you want to use multiple Checkbox components, in addition to adding multiple Checkbox components in the page, there is a relatively convenient way to use the CheckBoxList component. The CheckBoxList component is composed of a set of Checkbox components. Checkbox in this component is in the form of an entry, and there is an index number for each checkbox in the checkboxlist component, which is easier in the program. Treatment. At this time, you may have to ask, this is not a lot of this one, since there is a checkbox component, what is the CheckBoxList component? This is because in the process of programming, handling the CheckboxList component is often more prone to more and clearly more and more. Examples are as follows: Assume that there is a checkboxlist component and there are ten Checkbox components, and this CheckBoxList component is made up of this ten Checkbox components. In order to detect which of these ten Checkbox components have been selected, if the Checkbox component selected in the program requires the following code:
IF (c1. Checked) {} f (c2. check) {} .... if (c10. Checked) {}
But if you use the CheckBoxList component in the program, you only need the following lines of code:
For (int i = 0; i Note: Where C1-C10 is the Checkbox component, CHK is the CheckBoxList component, which is used by CheckBoxList components, which is indeed clearer in programming, and more concise. And as long as you have the usage of the CheckboxList component, the Usage of the Checkbox component will be roughly. One. How to create a CheckBoxList component: Add the above statement to the ASP.NET page, you can generate a CheckBoxList component named "C1". two. The properties that are often used in the checkboxlist component: I> .textalign attribute: Take the value: Left, Right. If the value of TextAlign is Left, the text of the check box in the checkboxlist component is on the left side of the box, the same reason If the value of TextAlign is Right, check the words of the check box on the right of the box. II> .selected attribute: is a Boolean, determines whether the checkbox in the component is selected. III> .repeatcolumns attribute: There are several check boxes in the checkboxlist component, which is primarily to set these check boxes to the bottom to display. IV> .repeAtDirection property: This property can be: Vertical, Horizontal. When the RepeatColumns property is set, it is set to set this property to arrange each check box in the component. details as follows: Assume that the CheckBoxList component has four check boxes, and the RepeatColumns property is 2. (1). If repeatdirection = veriTical, check the box in the page is as follows: Check box 01 check box 03 Check box 02 check box 04 (2). If Repeatorction = Horizontal, check the display of the box in the page is as follows: Check box 01 check box 02 Check box 03 check box 04 V> .count properties: Returns how much check boxes in the CheckBoxList component. three. Methods often use in the CheckBoxList component: (1). Add a check box in the component, the syntax is as follows: CHKLIST. ITEMS. Add (New ListItem ( (2). Access the check box in the component, the syntax is as follows: CHKList. Items [ (3). Delete check boxes in the component, the syntax is as follows: CHKLIST. Items. Remove ( four. An example introduces the method of use of the checkboxlist component: (1). How to determine which checkboxes in the component: In the program, it is done by processing the Selected attribute and count attributes, as follows: For (int i = 0; i (2). How to set the appearance layout of the CheckBoxList component: The checkboxlist component has a relatively large attribute to set its appearance. In the program introduced in this article, it is mainly to set the appearance layout of the component in four aspects: the sequence of texts in the checkbox in the component and the arrangement of the box Each check box layout in the component, the number of lines arranged in each check box in each check box in the component, and the specific program code is as follows: Switch (CBOALIGN. SELECTEDINDEX) {casual = textalign. Left; break; case 1: chklist.... // Component in each check box layout Switch (CBOREPEATLAYOUT. SELECTEDINDEX) {case 0: chklist. RepeatLayout = RepeatLayout. Table; Break; Case 1: chklist. REPEATLAYOUT = RepeatLAYout. Flow; Break;} // Component in each check box arrangement a direction switch (cboRepeatDirection SelectedIndex.) {case 0: ChkList RepeatDirection = RepeatDirection Vertical; break; case 1:.... ChkList RepeatDirection = RepeatDirection Horizontal; break;} // number of rows are arranged in each component of the checkbox try {int cols = int. parse (txtrepeatcols.text); chklist. REPEATCOLUMNS = cols;} catch (exception) {}. Sino - Source Program Code (Check.aspx) and Executive Interface: The figure below is to generate the interface: Check.aspx, the generated interface: Check.aspx source code code is as follows: <% @ Page language = "c #"%>