从数据库里查询数据,然后绑定DropDownList。如何让某一项处于选中状态呢,也就是默认DropDownList选显示哪一项?

代码如下:

ListItem item=ddlUsrLIst.Items.FindByText("刘备");

if(item != null)
{
item.Selected = true;
}

用FindByValue也行,具体看帮助。
那如何在指定位置添加一项呢?代码如下
ddlUsrList.Items.Insert(0,new ListItem("text","value"));
这里的0是项索引。
如:
ddlUsrList.Items.Insert(0,new ListItem("--请选择--","ddl的value"));

 

或者是

 

this.ddlclassid.SelectedValue = dr["classid"].ToString();

相关文章:

  • 2021-06-21
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2021-10-07
  • 2021-07-20
  • 2022-12-23
相关资源
相似解决方案