Asp.net|web| programming Five. The source code (check.aspx) and the execution interface:
The following figure is the resulting interface after executing the source code (check.aspx):
Check.aspx source code is as follows:
<% @ Page Language = "C #"%>
<title > CheckBoxList component Demo Program </title
<script runat = "server" >
protected void Button_Click (object sender, EventArgs e)
{
The placement of text and Marquee in the check box in the component
Switch (cboalign. SelectedIndex)
{
Case 0:
Chklist. TextAlign = TextAlign. Left;
break;
Case 1:
Chklist. TextAlign = TextAlign. right;
break;
}
Each check box layout in a component
Switch (cborepeatlayout. SelectedIndex)
{
Case 0:
Chklist. RepeatLayout = RepeatLayout. Table;
break;
Case 1:
Chklist. RepeatLayout = RepeatLayout. flow;
break;
}
Arrange direction for each check box in a component
Switch (cborepeatdirection. SelectedIndex)
{
Case 0:
Chklist. RepeatDirection = RepeatDirection. Vertical;
break;
Case 1:
Chklist. RepeatDirection = RepeatDirection. Horizontal;
break;
}
Number of rows to arrange for each check box in the component
Try
{
int cols = Int. Parse (Txtrepeatcols.text);
Chklist. RepeatColumns = cols;
}
catch (Exception)
{
}
Lblresult. Text = "";
for (int i = 0; I chklist. Items. Count; i++)
{
if (chklist. Items [i]. Selected)
{
Lblresult. Text + chklist. Items [i]. Text + "<BR >";
}
}
}
</script >
<body >
<form runat = "server" >
<table >
<TR >
<TD > text arrangement position in component: </TD >
<TD >
<asp:dropdownlist id = cboalign runat = "server" >
<asp:listitem > Ju Zuo </asp:listitem
<asp:listitem > right </asp:listitem >
</asp:dropdownlist >
</TD >
</TR >
<TR >
<TD > Individual item layouts in components: </TD >
<TD >
<asp:dropdownlist id = cborepeatlayout runat = "server" >
<asp:listitem > table-type </asp:listitem >
<asp:listitem > compact </asp:listitem >
</asp:dropdownlist >
</TD >
</TR >
<TR >
<td> the items in the component are arranged in the direction: </TD >
<TD >
<asp:dropdownlist id = cborepeatdirection runat = "server" >
<asp:listitem > horizontal direction </asp:listitem >
<asp:listitem > vertical direction </asp:listitem >
</asp:dropdownlist >
</TD >
</TR >
<TR >
<TD > Number of items in the component line: </TD >
<TD > <asp:textbox id = "Txtrepeatcols" runat = "server"/> </td
</TR >
</table >
<BR >
Please select the type of computer language you need to learn:
<BR >
<asp:checkboxlist id = "Chklist" RepeatDirection = horizontal runat = "server" >
<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 >
<BR >
<asp:button Text = "submit" runat = "server" onclick = "Button_Click"/>
<asp:label id = lblresult runat = "server"/>
</form >
</body >
Six Summarize:
In fact, the CheckBoxList component is also a server-side component. This article describes some of the major properties and methods in the CheckBoxList component, And through a more typical example of how to do with the CheckBoxList component in the ASP.net page programming, in fact, for another important component--checkbox, they have a lot of similarities, mastered the use of CheckBoxList components of the general control of the CH The use of Eckbox components.