国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

詳解ASP.NET控件之RadioButtonList

2024-07-10 12:54:20
字體:
來源:轉載
供稿:網(wǎng)友

有時候開發(fā)的項目是多個項目一起進行,所以需要更改程序中單選按鈕的數(shù)目,下面錯新技術頻道小編詳解ASP.NET控件之RadioButtonList,感興趣的朋友一起來看看。

“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 設置為 RepeatLayout.Table(默認設置),列表將呈現(xiàn)在表中。如果設置為 RepeatLayout.Flow,列表將不以表格形式呈現(xiàn)。默認情況下,RepeatDirection 設置為 RepeatDirection.Vertical。將該屬性設置為 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樣式調整?

.rblStyle{width:100%;height:auto;}
.rblStyle input{border-style:none;}?

3.onselectedindexchanged事件?

像下拉控件dropdownlist控件一樣,它也有onselectedindexchanged事件,當選項改變后進行觸發(fā)?

注意點是:控件中的AutoPostBack屬性一定設為"True",這樣服務器端才知道你的選項改變了,并觸發(fā)相應事件

4.為ListItem添加提示

RadioButtonList1.Items[0].Attributes.Add("title", "提示內容");

5.綁定數(shù)據(jù)源????????????

string sql = "select * from province";DataTable dt = SQLHelper.ExecuteDataTable(sql);this.RadioButtonList1.DataSource = dt;this.RadioButtonList1.DataTextField = "Provinces";this.RadioButtonList1.DataValueField = "PId";this.RadioButtonList1.DataBind();

6.改變選中項的前景色

<asp:RadioButtonList ID="rblIsLock" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rblIsLock_SelectedIndexChanged" RepeatDirection="Horizontal" RepeatLayout="Flow">   <asp:ListItem Selected="True" Value="0">啟用 </asp:ListItem>   <asp:ListItem Value="1">禁用 </asp:ListItem> </asp:RadioButtonList> <label>*禁用的用戶將無法登錄</label>

后臺:???

protected void rblIsLock_SelectedIndexChanged(object sender, EventArgs e) {  var rbl = sender as RadioButtonList;  HighliehgSelectedItem(rbl); } private void HighliehgSelectedItem(RadioButtonList rbl) {  foreach (ListItem li in rbl.Items)  {   if (li.Selected)   {   li.Attributes.Add("style", "color: red;");   }  } }

7.后臺動態(tài)增加RadioButtonList???

 RadioButtonList rbl = new RadioButtonList();   rbl.ID = "rbl" + (i + 1).ToString();   rbl.BorderStyle = BorderStyle.None;   rbl.RepeatLayout = RepeatLayout.Flow;   rbl.RepeatDirection = RepeatDirection.Horizontal;   rbl.TextAlign = TextAlign.Right;   rbl.CellSpacing = 6;   rbl.Attributes.Add("onclick", "CheckRbl('ctl00_ctl00_ctl00_ContentPlaceHolder1_cphBody_cphLower_" + rbl.ID + "')");   rbl.DataSource = dtRating.DefaultView;   rbl.DataTextField = "LevelID";   rbl.DataValueField = "LevelID";   rbl.DataBind();   tc.Controls.Add(rbl); //tc是TableRow的一個單元格TableCell    for (int k = 0; k < rbl.Items.Count; k++)   {   rbl.Items[k].Attributes.Add("title", dtRating.Rows[k][1].ToString());   rbl.Items[k].Attributes.Add("style", "margin-left:10px;");   }

8.前臺改變選中項的背景色?

  window.onload = function () {  var arr = document.getElementsByTagName("INPUT");  for (var i = 0; i < arr.length; i++) {  if (arr[i].checked) {   if (arr[i].type == "radio") {   arr[i].style.backgroundColor = "red";   }   else {   arr[i].style.backgroundColor = "";   }  }  else {   arr[i].style.backgroundColor = "";  }  } }上文錯新技術頻道小編為大家介紹了詳解ASP.NET控件之RadioButtonList,為了幫助更多朋友,我們整理了大量的相關資訊,感興趣的朋友可以關注js.VeVb.com。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 建平县| 商城县| 桂林市| 呼伦贝尔市| 乳山市| 巩留县| 本溪| 曲松县| 建水县| 天门市| 鸡西市| 随州市| 集安市| 无极县| 兴和县| 青铜峡市| 兴海县| 南江县| 新干县| 福安市| 晋中市| 江北区| 元氏县| 乌兰浩特市| 塔城市| 金秀| 肥东县| 珠海市| 威信县| 米泉市| 云龙县| 镇平县| 长泰县| 余干县| 哈巴河县| 马尔康县| 乌拉特中旗| 武汉市| 姚安县| 和平县| 和平县|