Solved

How to apply validation control in asp:radio button list

Posted on 2014-04-22
3
488 Views
Last Modified: 2014-05-09
I have the asp:radiobuttons
How to apply required validation control in such a way that the users access atleast one.

 <asp:RadioButtonList ID="RBL_mode" runat="server" AutoPostBack="True"
                            CssClass="report_color" onselectedindexchanged="RBL_mode_SelectedIndexChanged"
                            RepeatDirection="Horizontal" Width="674px">
                            <asp:ListItem Value="1" Selected="False">Monovalent RDT</asp:ListItem>
                             <asp:ListItem Value="11" Selected="False">Monovalent RDT+Slide</asp:ListItem>
                            <asp:ListItem Value="2" Selected="False">Bivalent RDT</asp:ListItem>
                             <asp:ListItem Value="22" Selected="False">Bivalent RDT+Slide</asp:ListItem>
                            <asp:ListItem Value="3" Selected="False">Referral</asp:ListItem>
                            <asp:ListItem Value="0" Selected="False">Slide only</asp:ListItem>
                        </asp:RadioButtonList>
0
Comment
Question by:searchsanjaysharma
3 Comments
 
LVL 5

Accepted Solution

by:
jayakrishnabh earned 250 total points
ID: 40016815
<asp:RadioButtonList ID="RBL_mode" runat="server" AutoPostBack="True" onselectedindexchanged="RBL_mode_SelectedIndexChanged"
                            CssClass="report_color" RepeatDirection="Horizontal" Width="674px">
                            <asp:ListItem Value="1" Selected="False">Monovalent RDT</asp:ListItem>
                             <asp:ListItem Value="11" Selected="False">Monovalent RDT+Slide</asp:ListItem>
                            <asp:ListItem Value="2" Selected="False">Bivalent RDT</asp:ListItem>
                             <asp:ListItem Value="22" Selected="False">Bivalent RDT+Slide</asp:ListItem>
                            <asp:ListItem Value="3" Selected="False">Referral</asp:ListItem>
                            <asp:ListItem Value="0" Selected="False">Slide only</asp:ListItem>
                        </asp:RadioButtonList>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="RBL_mode" Enabled="true"
             ValidationGroup="ValidationGroup1"></asp:RequiredFieldValidator>
        <asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="true" ValidationGroup="ValidationGroup1" />
0
 
LVL 12

Assisted Solution

by:duttcom
duttcom earned 250 total points
ID: 40016828
A RequiredFieldValidator for your list would look something like this-

<asp:RequiredFieldValidator runat="server" ErrorMessage="You must select at least one option!!!" ID="RBL_mode_validator" ControlToValidate="RBL_mode">
                </asp:RequiredFieldValidator>

This is a simple validator that will assume a starting value for the radiobuttonlist is null and requires that the value of the list changes in order for it to be valid. So this will work well for entering records for the first time, but not as well if you are editing records which already have a value (in which case you will need to do a custom validator with code to check that an option has been selected in the list).
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 40053310
tx
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now