DropDownList1.DataSource = 这里是查询出来的集合;         //指定DropDownList使用的表里的那些字段         DropDownList1.DataTextField = "表里的Name字段"; //dropdownlist的Text的字段         DropDownList1.DataValueField = "这里是一般放表里的ID做为value值";//dropdownlist的Value的字段         DropDownList1.DataBind();

解决方案 »

  1.   

    using(SqlConnection conn=new SqlConnection(""))
    {
    SqlDataAdapter sda = new SqlDataAdapter("select * from tb",conn);
    DataSet ds = new DataSet();
    sda.Fill(ds);
      DropDownList1.DataSource = ds;
       DropDownList1.DataTextField = "Name字段"; //dropdownlist的Text的字段
        DropDownList1.DataValueField = "value值";
        DropDownList1.DataBind();
    }
      

  2.   

    假如数据表name有个字段是field,下拉菜单里面需要的就是field的内容,各位能否给出完全代码,多谢了
      

  3.   

    还有一个更死的方法。using(SqlConnection conn=new SqlConnection(""))
    {
    SqlDataAdapter sda = new SqlDataAdapter("select name from name",conn);
    DataSet ds = new DataSet();
    sda.Fill(ds);for(int i=0;i<ds.Table[0].Rows.count;i++)
    {
    DropDownList1.Item.Add(ds.Table[0].Rows[i][0].tostring());
    }
    }
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;namespace test
    {
        public partial class Form3 : Form
        {
            public Form3()
            {
                InitializeComponent();
            }
            /// <summary>
            /// 获取数据,返回dataset,用来绑定到下拉列表中
            /// </summary>
            public DataSet getData()
            {
                DataSet ds = null;
                using (SqlConnection con = new SqlConnection("server=172.16.8.116;database=test;uid=sa;pwd=888888"))
                { 
                    string sql="select name from names";//name 是表 names中的字段
                    using (SqlCommand cmd = new SqlCommand(sql, con))
                    {
                        if (!string.IsNullOrEmpty(sql))
                        {
                            SqlDataAdapter sda = new SqlDataAdapter(cmd);
                            ds = new DataSet();
                            sda.Fill(ds);
                        }
                    }
                }
                return ds;
            }        private void Form3_Load(object sender, EventArgs e)
            {
                this.comboBox1.DisplayMember = "name";//设置显示的是表中的哪一列
                this.comboBox1.DataSource = getData().Tables[0];//绑定数据源
               
            }
        }
    }
    希望这些能够帮助你,这个是winform中的,web中的跟它原理一模一样,希望你能理解
      

  5.   

    上頂,DORPDOWNLIST 綁定就OK了···