zoukankan      html  css  js  c++  java
  • RadioButtonList

    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 控件的绑定

    View Code
    前台:
    
    <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.当选项被选中时,更改选中选项的前景色

    View Code
     <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;");
                }
            }
        }
  • 相关阅读:
    hibernate关联关系映射
    java单例模式
    HTML如何给table添加滚动条
    jquery的几种ajax方式对比
    JQuery Selectors 方法说明
    jQuery遍历对象/数组/集合
    Jquery常用函数
    【刷题】【省选】ZJOI2017_仙人掌_LOJ2250/Luogu3687_圆方树/dp计数/树形dp
    【学习笔记】圆方树学习笔记
    【模板】【刷题】差分与前缀和_LuoguP5488_多项式
  • 原文地址:https://www.cnblogs.com/LifeKingcn/p/2825120.html
Copyright © 2011-2022 走看看