给asp:DropDownList追加项到顶层显示

/// <summary>
    /// 绑定默认信息
    /// </summary>
    private void datebins()
    {
        Tb_objAdminInfo info = new Tb_objAdminInfo();

        Tb_objAdminHelper helpe = new Tb_objAdminHelper();
        drpXMName.DataSource = helpe.GetAllList(info);
        drpXMName.DataBind();

        drpXMName.AppendDataBoundItems = true;//次行代码如果直接出现在页面,有可能会导致数据重复显示
        this.drpXMName.Items.Insert(0, new ListItem("--请选择--", "--请选择--"));
        //BLL.gueatManager manag = new gueatManager();

        Tb_companyHelper chelper = new Tb_companyHelper();
        Tb_companyInfo cInfo = new Tb_companyInfo();
       
        this.dropMF1.DataSource = chelper.GetAllList(cInfo);
        this.dropMF1.DataBind();

        this.dropMF1.AppendDataBoundItems = true;
        this.dropMF1.Items.Insert(0, new ListItem("--请选择--", "--请选择--"));
        //this.dropMF1.Items.Add(new ListItem("--请选择--", "--请选择--"));
        //this.dropMF1.SelectedValue = "南昌通服科技有限公司";

    }

手动修改DropDownList选择项的时候
AppendDataBoundItems属性要设置为True

修改为true也可以实现,这个属性的意思是可以再已有项的前提下添加新项,而不改变原来项!

写的不对的地方期望高人指点一二!

原文地址:https://www.cnblogs.com/huanhuan86/p/2369616.html