Wednesday, May 21, 2008

How to Validate CheckListBox

Create Page has CheckListBox (cbx_Application) and CustomValidator and button Control

and In Event Server_Control of Custom Validator write the following Code:

protected void User_Choice(object source, ServerValidateEventArgs args)
{
int counter = 0;
for (int i = 0; i < cbx_Application.Items.Count; i++)
{
if (cbx_Application.Items[i].Selected)
{
counter++;
}
args.IsValid = (counter == 0) ? false : true;
}

No comments: