dropdownlist.datasuorce=tablename; 
dropdownlist.DataTextField = "你要显示的字段名"; 
dropdownlist.DataValueField = "你要存值的字段名"; 
dropdownlist.DataBind();

解决方案 »

  1.   

    if(DDL_country.Items.Count==0)                           //从数据库取出数据填充下拉列表框
    {
    SqlConnection conn = new SqlConnection(WLIB.SqlCnStr);
    string str_coun="select country_name,country_code from dmb_coun order by country_name";
    SqlDataAdapter Myunitadp = new SqlDataAdapter(str_coun,conn);
    DataSet ds_coun=new DataSet();
    DDL_country.DataSource=ds_coun;
    DDL_country.DataTextField="country_name";
    DDL_country.DataValueField="country_code";
    conn.Open();
    Myunitadp.Fill(ds_coun);
    DDL_country.DataBind();
    DDL_country.SelectedIndex=0;
    conn.Close();
    }
      

  2.   

    指定dropDownList的以下几个属性:
    dropdownlist.datasuorce=DataSet;
    dropDownList.DataMember=DataTableName; 
    dropdownlist.DataTextField = "你要显示的字段名"; 
    dropdownlist.DataValueField = "你要存值的字段名"; 然后在Page_load()
    {
    if(!IsPostBack)
    {
    dropdownlist.DataBind();
    }}
      

  3.   

    dropdownlist.datasuorce应该如何赋值
      

  4.   

    这样赋值:
    DataSet ds = new DataSet();
    DropDownList.DataSource = ds;
      

  5.   

    我的代码有什么问题?请赐教!!
    其中CDB112中我已经定义好了,连接
    string sql_zaxx;
    sql_zaxx="select * from dic_matter";
    CDB112 newmat= new CDB112();
    System.Data.OleDb.OleDbDataReader eader=null;
    newmat.MakeDataSet(ref myreader, sql_zaxx);
    dropdl_zaxx.DataSource=myreader; 
    dropdl_zaxx.DataMember=dic_matter; 
    dropdl_zaxx.DataTextField = "matter_name"; 
    dropdl_zaxx.DataValueField = "matter_id"; 
    dropdl_zaxx.DataBind(); if (myreader == null)
    return;

    this.dropdl_zaxx.DataSource=myreader;
    this.dropdl_zaxx.DataBind();
      

  6.   

    private void RiBindDataToList()
    {
        SqlCommand Comm=new SqlCommand("select CustMngrID,CustMngrName from T_CUST_MNGR where ChargeID=@cid",Conn);
    Comm.Parameters.Add("@Cid",SqlDbType.VarChar);
    Comm.Parameters["@Cid"].Value=MangID;
    if(Conn.State.ToString()!="Open")
    Conn.Open();
    try
    {
    SqlDataReader Reader=Comm.ExecuteReader();
    DropDownList1.DataValueField="CustMngrID";
    DropDownList1.DataTextField="CustMngrName";
    DropDownList1.DataSource=Reader;
    DropDownList1.DataBind();
    Reader.Close();
    }
      

  7.   

    我的数据库是oracle,不是sqlserver
    谁能给个例子
      

  8.   

    直接指定源不好写WHERE条件,下面这么写可以通过复杂的SQL直接抽出最后结果,而且绑多个域Dim SQL As String
    Dim Dynaset As Object
    Dim OraDatabase As ObjectSQL = "SELECT field1, field2 ..."
    Dynaset = OraDatabase.DbCreateDynaset(SQL, 0)
    Dynaset.DbMoveFirst()
    Do Until Dynaset.EOF
        DropDownList1.Items.Add(Dynaset.Fields("field1").Value & " " & Dynaset.Fields("field2").Value)
        Dynaset.MoveNext()
    Loop
    然后在Page_load()
    if(!IsPostBack)
    {
    dropdownlist1.DataBind();
    }