Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to apply validation control in asp:radio button list

Posted on 2014-04-22
3
Medium Priority
?
553 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 750 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 750 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

885 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