茶树

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

DropDownList在从数据库中得到数据源绑定后,添加一个"请选择"或"全部"之类的项

 

1:直接添加:<asp:ListItem Value="0">请选择</asp:ListItem>,然后在DropDownList中添加一个属性:  AppendDataBoundItems="True"

 示例:1

<asp:DropDownList  ID="ddlAll" runat="server" AutoPostBack="true"

onselectedindexchanged="ddlDepartment_SelectedIndexChanged" DataTextField="DeptName" 

AppendDataBoundItems="True"  DataValueField="DeptID">

<asp:ListItem Value="0">请选择</asp:ListItem>

</asp:DropDownList>

 


实例 2:在后台代码CS文件添加:

ddlAll.Items.Insert(0, new ListItem("-请选择-", "0"));

添加以后,在使用的时候:

If(ddlAll.SelectedValue!="0")

{

deptId=ddlAll.SelectedValue;

}

posted on 2016-05-18 14:09  "茶树"  阅读(515)  评论(0编辑  收藏  举报