关于DropDownList绑定数据后,怎么添加另外的默认值

 

 

if (!IsPostBack)
{
  InitDrop();//绑定名称
}

  //绑定dropdownlist数据
  private void InitDrop()
  {
  dropdownlist1.Items.Clear();
  string sql = "select t.* from rylb t ";
  DataTable dt = db.GetData.ExecuteTable(sql);
  dropdownlist1.DataSource = dt;
  dropdownlist1.DataTextField = "name";
  dropdownlist1.DataValueField = "id";
  dropdownlist1.DataBind();
  dropdownlist1.Items.Insert(0, new ListItem("--请选择--", ""));

dropdownlist1.Items.FindByText( "--请选择--").Selected   =   true;

  }

 

    /// <summary>
    /// 绑定部门
    /// </summary>
    void BindDepartment()
    {
        UzaiAdminBusinessGroup model = new UzaiAdminBusinessGroup();
        model.AdminBusinessGroupID = 0;
        model.AdminBusinessGroupParentID = -1;

        
        List<UzaiAdminBusinessGroup> list =  bll.GetAdminGroup(model);
        ddlDepartment.DataSource = list;
        ddlDepartment.DataValueField = "AdminBusinessGroupID";
        ddlDepartment.DataTextField = "AdminBusinessGroupName";
        ddlDepartment.DataBind();
        ddlDepartment.Items.Insert(0,new ListItem { Text = "请选择", Value = "0" });
        ddlDepartment.SelectedItem.Selected = true;
        
    }



参考地址1:http://topic.csdn.net/u/20100508/14/7f57a1e7-1b56-4af2-bafc-913230daf011.html

参考地址2:http://topic.csdn.net/t/20050425/11/3964179.html

你可能感兴趣的:(sql,String,2010)