首页 .NET/Web RadioButtonList 动态读取 如何让RadioButtonList默认选中第一个

RadioButtonList 动态读取 如何让RadioButtonList默认选中第一个

作者:胡同里的砖头 围观群众:1181 更新于:2013-12-19

 protected void MainDerection()
    {
        DataTable myDt = new DataTable();
        myDt = myBU_UserInfo.MainDerectionBind();
        this.rdoListMainDirection.DataSource = myDt;
        rdoListMainDirection.DataTextField = "DataCaption";
        rdoListMainDirection.DataValueField = "ID";
        rdoListMainDirection.DataBind();
       rdoListMainDirection.Items[0].Selected = true; //默认选中第一个
    }

RadioButtonList的数据是从数据库动态绑定的,怎么设置第一项为默认选中?还有就是怎么用户判定选中了那个?

[code=C#]    protected void Page_Load(object sender, EventArgs e)
   {
       
        String []args
={ "a", "b"
};
        RadioButtonList1.DataSource
=
args;
        RadioButtonList1.DataBind();               
//绑定


        RadioButtonList1.Items[
0].Selected = true; //设定选中 //html
    }
   
protected void Button1_Click(object
sender, EventArgs e)
    {
       
foreach (ListItem item in
RadioButtonList1.Items)
        {
           
if(item.Selected)   //判断选中

                Response.Write("<br>" + item.Text+item.Value );
        }
    }

CheckButtonList   同理咯

  • 本文标题: RadioButtonList 动态读取 如何让RadioButtonList默认选中第一个
  • 文章分类:【.NET/Web】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8