1.用法
<asp:RadioButtonList ID="rblIsLock" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow"> <asp:ListItem Selected="True" Value="0">啟用 </asp:ListItem> <asp:ListItem Value="1">禁用 </asp:ListItem> </asp:RadioButtonList><label>*禁用的用戶將無法登錄</label>
2.RadioButtonList控件里的每項asp:ListItem添加單獨的ToolTip也就是鼠標懸停的提示信息
protected void Page_Load(object sender, EventArgs e) { RadioButtonList1.Items[0].Attributes.Add("title", "111"); RadioButtonList1.Items[1].Attributes.Add("title", "111"); }
3.使用復雜綁定完成 CheckBoxList 和 RadioButtonList 控件的綁定

前台: <body> <form id="form1" runat="server"> <div> <asp:RadioButtonList ID="RadioButtonList1" runat="server"> </asp:RadioButtonList> <br /> <br /> <asp:CheckBoxList ID="CheckBoxList1" runat="server"> </asp:CheckBoxList> </div> </form> </body> 后台: protected void Page_Load(object sender, EventArgs e) { 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(); this.CheckBoxList1.DataSource = dt; this.CheckBoxList1.DataTextField = "Provinces"; this.CheckBoxList1.DataValueField = "PId"; this.CheckBoxList1.DataBind(); } SQLHelper類: public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pms) { DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(sql,connStr); if (pms != null) { adapter.SelectCommand.Parameters.AddRange(pms); } adapter.Fill(dt); return dt; }
4.當選項被選中時,更改選中選項的前景色

<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;"); } } }