Attributes frequently used in the ASP. NET checkboxlist component:
I. textalign attributes: The value is left or right. If the value of textalign is left, the text of the check box in the checkboxlist component is on the left of the check box. Similarly, if the value of textalign is right, the text of the check box is on the right of the check box.
Ii. Selected attribute: boolean type, used to determine whether the check box in the component is selected.
Iii. repeatcolumns attributes: There are several check boxes in the checkboxlist component. This attribute mainly sets how many rows are used to display these check boxes.
Iv. repeatdirection attribute: the value of this attribute can be vertical or horizontal. After the repeatcolumns attribute is set, it is set to arrange the check boxes in the component. The details are as follows:
Assume that the checkboxlist component has four check boxes and the repeatcolumns attribute value is 2.
(1). If repeatdirection = vertical, check the box display on the page as follows:
Check box 01 check box 03
Check box 02 check box 04
(2) If repeatdirection = horizontal, check the box display on the page as follows:
Check box 01 check box 02
Check box 03 check box 04
V. Count attribute: return the number of check boxes in the checkboxlist component.
Iii. methods frequently used in ASP. NET checkboxlist component programming:
(1) Add a check box to the component. The syntax is as follows:
- Chklist. Items. Add (New listitem (<text >,< value> ))
(2). Access the check box in the component. The syntax is as follows:
- Chklist. items [<index>]
(3). Delete the check box in the component. The syntax is as follows:
- Chklist. Items. Remove (<index>)
4. The example introduces how to use the ASP. NET checkboxlist component:
(1). How to determine which check boxes are selected for the component:
In a program, the selected Attribute and count attribute are processed as follows:
- For (INT I = 0; I <chklist. Items. Count; I ++)
- {
- If (chklist. items [I]. Selected)
- {
- Lblresult. Text + = chklist. items [I]. Text + & quot ;;
- }
- }
(2) how to set the appearance layout of the ASP. NET checkboxlist component:
The checkboxlist component has many attributes to set its appearance. In the program described in this article, the component's appearance layout is mainly set through four aspects: the text in the check box and the position of the check box in the component, the layout of each check box in the component,
The check box arrangement direction in the component and the number of lines in each check box in the component. The specific program code is as follows:
- // The text in the check box and the position of the check box in the component
- Switch (cboalign. selectedindex)
- {
- Case 0:
- Chklist. textalign = textalign. Left;
- Break;
- Case 1:
- Chklist. textalign = textalign. Right;
- Break;
- }
- // Check box layout in the component
- Switch (cborepeatlayout. selectedindex)
- {
- Case 0:
- Chklist. repeatlayout = repeatlayout. Table;
- Break;
- Case 1:
- Chklist. repeatlayout = repeatlayout. flow;
- Break;
- }
- // Check box arrangement direction in the component
- Switch (cborepeatdirection. selectedindex)
- {
- Case 0:
- Chklist. repeatdirection = repeatdirection. vertical;
- Break;
- Case 1:
- Chklist. repeatdirection = repeatdirection. horizontal;
- Break;
- }
- // The number of lines in each check box in the component
- Try
- {
- Int Cols = int. parse (txtrepeatcols. Text );
- Chklist. repeatcolumns = Cols;
- }
- Catch (exception)
- {
- }
5. source code in the text (check. aspx ):
Check. aspx source code is as follows:
- <%@ Page Language = & quot; C # & quot; %>
- <HTML>
- <Head>
- <Title> checkboxlist component demo program </title>
- <SCRIPT runat = & quot; server & quot;>
- Protected void button_click (
Object sender, eventargs E)
- {
- // The text in the check box and the position of the check box in the component
- Switch (cboalign. selectedindex)
- {
- Case 0:
- Chklist. textalign = textalign. Left;
- Break;
- Case 1:
- Chklist. textalign = textalign. Right;
- Break;
- }
- // Check box layout in the component
- Switch (cborepeatlayout. selectedindex)
- {
- Case 0:
- Chklist. repeatlayout = repeatlayout. Table;
- Break;
- Case 1:
- Chklist. repeatlayout = repeatlayout. flow;
- Break;
- }
- // Check box arrangement direction in the component
- Switch (cborepeatdirection. selectedindex)
- {
- Case 0:
- Chklist. repeatdirection = repeatdirection. vertical;
- Break;
- Case 1:
- Chklist. repeatdirection = repeatdirection. horizontal;
- Break;
- }
- // The number of lines in each check box in the component
- Try
- {
- Int Cols = int. parse (txtrepeatcols. Text );
- Chklist. repeatcolumns = Cols;
- }
- Catch (exception)
- {
- }
- Lblresult. Text = & quot ;;
- For (INT I = 0; I <chklist. Items. Count; I ++)
- {
- If (chklist. items [I]. Selected)
- {
- Lblresult. Text + = chklist. items [I]. Text + & quot ;;
- }
- }
- }
- </SCRIPT>
- </Head>
- <Body>
- <Form runat = & quot; server & quot;>
- <H1 align = center> checkboxlist component demo program
- <Table>
- <Tr>
- <TD> text placement in the component: </TD>
- <TD>
- <Asp: dropdownlist id = cboalign runat = & quot; server & quot;>
- <Asp: listitem> left </ASP: listitem>
- <Asp: listitem> right </ASP: listitem>
- </ASP: dropdownlist>
- </TD>
- </Tr>
- <Tr>
- <TD> layout of entries in the component: </TD>
- <TD>
- <Asp: dropdownlist id = cborepeatlayout runat = & quot; server & quot;>
- <Asp: listitem> table Type </ASP: listitem>
- <Asp: listitem> compact </ASP: listitem>
- </ASP: dropdownlist>
- </TD>
- </Tr>
- <Tr>
- <TD> the direction of each entry in the component: </TD>
- <TD>
- <Asp: dropdownlist id = cborepeatdirection runat = & quot; server & quot;>
- <Asp: listitem> horizontal direction </ASP: listitem>
- <Asp: listitem> vertical direction </ASP: listitem>
- </ASP: dropdownlist>
- </TD>
- </Tr>
- <Tr>
- <TD> Number of lines in each entry in the component: </TD>
- <TD> <asp: textbox id = & quot; txtrepeatcols & quot; runat = & quot; server & quot;/> </TD>
- </Tr>
- </Table>
Select the computer language type you want to learn:
- <Asp: checkboxlist id = & quot; chklist & quot; repeatdirection = horizontal runat = & quot; server & quot;>
- <Asp: listitem> visual
C ++. Net </ASP: listitem>
- <Asp: listitem> visual
C # </ASP: listitem>
- <Asp: listitem> VB. NET </ASP: listitem>
- <Asp: listitem> JScript. Net </ASP: listitem>
- <Asp: listitem> Visual J # </ASP: listitem>
- </ASP: checkboxlist>
- <Asp: button text = & quot; Submit & quot; runat = & quot; server & quot; onclick = & quot; button_click & quot;/>
- <H1> <font color = Red> the computer language type you selected is: </font>
- <Asp: Label id = lblresult runat = & quot; server & quot;/>
- </Form>
- </Body>
- </Html>