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】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.