Click here to Skip to main content
15,887,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
This is my issue I have group of radion buttons and I want to when someone of them is not seleted to display error message. This is the code that I have
<pre><div class="floatLeft ml_15">
                                <asp:Literal ID="litPatientTypeO9" runat="server"></asp:Literal> *
                                <br />
                                <asp:RadioButton ID="rbtnNewO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
                                <br />
                                <asp:RadioButton ID="rbtnRecidedO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
                                <br />
                                <asp:RadioButton ID="rbtnUnsucessfulyTreatedO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
                                <br />
                                <asp:RadioButton ID="rbtnTreatedAfterBrakeO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
                                <br />
                                <asp:RadioButton ID="rbtnMovedO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
                                <br />
                                <div id="divOtherType09" runat="server" class="floatLeft" style="padding-top: 3px;">
                                    <asp:RadioButton ID="rbtnOtherTypeO9" runat="server" 
                                        GroupName="PatientTypeO9" OnCheckedChanged="rbtnrbtnOtherTypeO9_CheckedChanged" AutoPostBack="true" CssClass="checkBox" />
                                </div>
                                <div class="floatLeft">
                                    <uc1:TextBoxControl ID="txtOtherTypeO9" runat="server" />
                                </div>
                            </div>


Thank you

What I have tried:

I look up trought internet, codeproject, stackoverfllow and msd forums and cannot find solution for me.
Posted
Updated 9-Apr-19 1:02am

1 solution

Here instead of using all the radio buttons separately, it is appropriate to use the radio button list. Prepare a data table for the data you want to display and bind it with radio button list like following:

RadioButtonList1.DataSource = dt;
                RadioButtonList1.DataTextField = "shortCode";
                RadioButtonList1.DataValueField = "longName";
                RadioButtonList1.DataBind();


You can also give same column to both data text field and data value field.
So, the main use of radio button list is that you can check the selected index.

RadioButtonList1.SelectedIndex != -1


If it is not -1, then any of radio button is selected else none is selected.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900