Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CheckBoxList Server Side Validation

Posted on 2013-01-14
4
Medium Priority
?
390 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 1000 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 1000 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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

715 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