未选择单选按钮时显示消息 [英] Display a message when radio button is not selected

查看:96
本文介绍了未选择单选按钮时显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

这是我的问题我有一组radion按钮,我想当他们中的某人没有选择显示错误信息时。这是我的代码

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>





谢谢



我尝试了什么:



我查找了互联网,codeproject,stackoverfllow和msd论坛,无法为我找到解决方案。



Thank you

What I have tried:

I look up trought internet, codeproject, stackoverfllow and msd forums and cannot find solution for me.

推荐答案

此处不是单独使用所有单选按钮,而是使用单选按钮列表。准备要显示的数据的数据表,并将其与单选按钮列表绑定如下:



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





如果不是-1,则选择任何单选按钮,否则选择无。



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


这篇关于未选择单选按钮时显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆