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()方法后
        }

  

转载于:https://www.cnblogs.com/gonghui2016/p/11607176.html

你可能感兴趣的:(DropDownList绑定数据源后,要插入项的处理)