“RadioButtonList”控件表示一個封裝了一組單選按鈕控件的列表控件。
可以使用兩種類型的 ASP.NET 控件將單選按鈕添加到網(wǎng)頁上:各個“RadioButton”控件或一個“RadioButtonList”控件。這兩類控件都允許用戶從一小組互相排斥的預定義選項中進行選擇。使用這些控件,可定義任意數(shù)目的帶標簽的單選按鈕,并將它們水平或垂直排列。
命名空間:System.Web.UI.WebControls
程序集:System.Web(在 system.web.dll 中)
[ValidationPropertyAttribute("SelectedItem")]
public class RadioButtonList : ListControl, IRepeatInfoUser, INamingContainer, IPostBackDataHandler
RadioButtonList 控件為網(wǎng)頁開發(fā)人員提供了一組單選按鈕,這些按鈕可以通過數(shù)據(jù)綁定動態(tài)生成。該控件包含一個 Items 集合,集合中的成員與列表中的各項相對應。若要確定選擇了哪一項,請測試列表的 SelectedItem 屬性。
可以用 RepeatLayout 和 RepeatDirection 屬性指定如何呈現(xiàn)列表。如果將 RepeatLayout 設(shè)置為 RepeatLayout.Table(默認設(shè)置),列表將呈現(xiàn)在表中。如果設(shè)置為 RepeatLayout.Flow,列表將不以表格形式呈現(xiàn)。默認情況下,RepeatDirection 設(shè)置為 RepeatDirection.Vertical。將該屬性設(shè)置為 RepeatDirection.Horizontal 時,列表將水平呈現(xiàn)。
RadioButtonList用法:
<div class="rblStyle">
<asp:RadioButtonList ID="rblChangQHT" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="是" Value="1"></asp:ListItem>
<asp:ListItem Text="否" Value="0"></asp:ListItem>
</asp:RadioButtonList></div>
1.RadioButtonList 校驗
var rb_ChangQHT = document.getElementById("rblChangQHT"); var ShiF = rb_ChangQHT.getElementsByTagName("INPUT"); var result = false; for (var i = 0; i < ShiF.length; i++) { if (ShiF[i].checked) { result = true; break; } } if (!result) { alert("是否為中長期合同為必填項!"); return false; }2.RadioButtonList樣式調(diào)整
.rblStyle{width:100%;height:auto;}
.rblStyle input{border-style:none;}
3.onselectedindexchanged事件
像下拉控件dropdownlist控件一樣,它也有onselectedindexchanged事件,當選項改變后進行觸發(fā)
注意點是:控件中的AutoPostBack屬性一定設(shè)為"True",這樣服務器端才知道你的選項改變了,并觸發(fā)相應事件
新聞熱點
疑難解答
圖片精選