且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

未选择单选按钮时显示消息

更新时间:2021-11-04 22:36:01

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



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.