zoukankan      html  css  js  c++  java
  • (开发篇) 控件研究~ 下拉列表中添加一条默认的选项 "请选择"

    界面上的内容

    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";   
  • 相关阅读:
    Math.pow
    css3正方体
    制作一个百度换肤效果
    排他思想
    js栈和堆的区别
    js创建对象的几种方式(工厂模式、构造函数模式、原型模式)
    短网址
    this
    作用域
    JS 函数基础
  • 原文地址:https://www.cnblogs.com/phoenixfling/p/2487140.html
Copyright © 2011-2022 走看看