请大家帮忙。显示部门。value=departmentId,text=departmentName

解决方案 »

  1.   

    需要设置DisplayMember和ValueMember,参看
    http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c43c.aspx#q561q
      

  2.   

    OleDbConnection myconn=new OleDbConnection(Base.Base.getConnectionString());
    OleDbCommand mycmd5=new OleDbCommand("",myconn);
    myconn.Open();
    OleDbDataReader myreader5;
    mycmd5.CommandText="select * from BDJ09,DJ08  where H02=I02 and I23='"+t1.Text+"'";
    myreader5=mycmd5.ExecuteReader();
    DropDownList1.DataSource=myreader5;
    DropDownList1.DataTextField="H01";
    DropDownList1.DataValueField="H01";
    DropDownList1.DataBind();
    myreader5.Close();
    myconn.Close();其中DataValueField=departmentId;DataTextField=departmentName;
      

  3.   

    SqlDataAdapter cmd=new SqlDataAdapter(SqlCmd,Conn);
    ds=new DataSet();
    this.Conn.Open();
    cmd.Fill(ds,"news");
    this.Conn.Close();
    DataTable dt=ds.Tables[0];
    DropDownList1.DataSource=dt.DefaultView;
    DropDownList1.DataValueField=dt.Columns["departmentId"].ToString();
    DropDownList1.DataTextField=dt.Columns["departmentName"].ToString();
    DropDownList1.DataBind();
      

  4.   

    感觉  syf2000119(ff) 这位朋友贴的代码是最好的,不过他代码里面的Text和Value共用了一个字段,其他很清晰明了