DropDownList绑定数据源后,要插入项的处理

 private void BindDivision()
        {
            DivisionService divisionService = new DivisionService();
            var divisions = divisionService.GetList(base.AdminDivisionId)
                .Select(x => new { Id = x.Id, Name = x.Name })
                .OrderBy(x => x.Name)
                .ToList();
            
            ddlDestinationCompany.DataSource = divisions;
            ddlDestinationCompany.DataTextField = "Name";
            ddlDestinationCompany.DataValueField = "Id";
            ddlDestinationCompany.DataBind();
            if (!base.AdminDivisionId.HasValue) ddlDestinationCompany.Items.Insert(0, new ListItem("请选择", ""));//注意:插入项必须位于绑定数据源后面,即DataBind()方法后
        }

  

posted @ 2019-09-29 12:22  enjoryWeb  阅读(162)  评论(0编辑  收藏  举报