<head>
<title>Setting Layout Direction in a CheckBoxList Control</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void Page_Load ( object src, EventArgs e ) {
if ( !IsPostBack ) {
msg.Text = "";
myList.SelectedIndex = -1;
}
}
void getSelected ( object src, EventArgs e ) {
// initialize variables
msg.Text = "";
int n = 0;
string s = "Selected items: ";
foreach ( ListItem item in myList.Items ) {
if ( item.Selected ) {
// list the selected items
s += item.Text + " ";
n ++;
}
}
if ( n > 0 ) msg.Text = s;
else msg.Text = "Nothing selected.";
}
void setDirection ( object src, EventArgs e ) {
if ( chkDirection.Checked )
myList.RepeatDirection = RepeatDirection.Horizontal;
else
myList.RepeatDirection = RepeatDirection.Vertical;
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Setting Layout Direction in a CheckBoxList Control</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<center>
<form runat="server">
<br>
<table cellpadding=10 bgcolor="beige" border>
<tr align="center"><td>
<asp:checkboxlist id="myList" repeatcolumns=3 cellspacing=10 runat="server">
<asp:listitem>Earth</asp:listitem>
<asp:listitem>Jupiter</asp:listitem>
<asp:listitem>Mars</asp:listitem>
<asp:listitem>Mercury</asp:listitem>
<asp:listitem>Neptune</asp:listitem>
<asp:listitem>Pluto</asp:listitem>
<asp:listitem>Saturn</asp:listitem>
<asp:listitem>Uranus</asp:listitem>
<asp:listitem>Venus</asp:listitem>
</asp:checkboxlist>
</td></tr>
<tr align="center"><td>
<asp:checkbox id="chkDirection" onCheckedChanged="setDirection" text="Display Horizontally" autopostback runat="server" />
</td></tr>
<tr align="center"><td>
<p><asp:button id="myButton" text="Submit" onClick="getSelected" runat="server" />
</td></tr>
</table>
<p><asp:label id="msg" runat="server" />
</form>
</center>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>