ajax toolkit Archives - Digital Tool Factory blog ajax toolkit Archives - Digital Tool Factory blog

The Digital Tool Factory Blog

How to set up the CheckBoxList control in Asp.net

I recently came up with the need to have a validated CheckBoxList in and Asp.net page.  Over the years I’ve come up with a standard way of setting up validated CheckBoxLists, so I thought I would share the method and start the brand new “Code Samples” section..

The aspx code is as follows

<strong>Section Name</strong>
<asp:TextBox ID="tbBox" runat="server" Width="1" BorderColor="White" BackColor="White" BorderStyle="None" />
<asp:CustomValidator ID="cvBox" ValidateEmptyText="true" runat="server" ControlToValidate="tbBox" Display="none" ErrorMessage="<b>Required Field Missing</b><br />You must select at least one option" SetFocusOnError="true" ValidationGroup="Main" onservervalidate="cvBox_ServerValidate" />
<ajaxToolkit:ValidatorCalloutExtender ID="vceBox" runat="server" TargetControlID="cvBox" Width="300" />

<br />

<asp:CheckBoxList ID=”cblForms” runat=”server” RepeatColumns=”2″ RepeatDirection=”Horizontal”>
<asp:ListItem Text=”Option A” Value=”A” />
<asp:ListItem Text=”Option B” Value=”B” />
<asp:ListItem Text=”Option C” Value=”C” />
<asp:ListItem Text=”Option D” Value=”D” />
</asp:CheckBoxList>

Please note, the control that I am validating is actually a 1 pixel wide textbox that one should not type in. Continue reading →


14
Jan 10


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.