(开发篇) 控件研究~ 下拉列表中添加一条默认的选项 "-请选择-"

界面上的内容

1         <asp:DropDownList ID="company" runat="server" AppendDataBoundItems=true>

2             <asp:ListItem Selected="true">-请选择-</asp:ListItem>

3         </asp:DropDownList>

后台代码

1         for (int i = company.Items.Count - 1; i > 0; i--)

2         {

3             company.Items.RemoveAt(i);

4         }

5         this.company.DataSource = ds_company;

6         this.company.DataValueField = "department_no";

7         this.company.DataTextField = "department_name";

8         this.company.DataBind();

解析:

  1.下拉列表中要添加 AppendDataBoundItems=true 属性

 

或者: 

            this.company.DataSource = ds_company;

            this.company.DataValueField = "department_no";

            this.company.DataTextField = "department_name";

            this.company.DataBind();



            this.company.Items.Add(new ListItem("请选择", "000000000"));

            this.company.SelectedValue = "000000000";   

 

 

 

 

你可能感兴趣的:(下拉列表)