Solved

CheckBoxList Server Side Validation

Posted on 2013-01-14
4
384 Views
Last Modified: 2013-01-22
Hello Experts,

I have a CheckBoxList control that retrieves data from my DB (works fine). But I need to make sure a user selects at least one value from the CheckBoxList before he/she can submit the form. If he/she does not select at least one value then I want to display a message saying "Please select at least one value".

Thanks in advance!!!
0
Comment
Question by:asp_net2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 38775353
0
 
LVL 4

Author Comment

by:asp_net2
ID: 38775512
I already have a Javascript/jQuery solution. I need a Server Side solution. Thank  you for your help though.
0
 
LVL 21

Accepted Solution

by:
masterpass earned 250 total points
ID: 38776138
you can use a customvalidator and then check onservervalidate event. Below is an example

http://briancaos.wordpress.com/2012/08/16/validate-aspcheckboxlist-with-aspcustomvalidator/

hope this helps.
0
 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 250 total points
ID: 38779195
Is it something like this you are looking for?
bool itemSelected = false;
            foreach (ListItem item in chk1.Items)
            {
                if (item.Selected)
                {
                    itemSelected = true;
                    break;
                }
            }
            if (!itemSelected)
            {
                // Write code for alert message here
            }

Open in new window

0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question