可以直接用DataReader,比如
SqlConnection con=new SqlConnection("...");
SqlCommand cmd=new SqlCommand("select id,name from yourtable",con);
SqlDataReader dataReader=cmd.ExecuteReader();
DropDownList1.DataSource=dataReader;
DropDownList1.DataTextField="name";
DropDwonList1.DataValueField="id";
DropDwonList1.DataBind();
con.Close();

解决方案 »

  1.   

    选择
    string id=DropDownList1.SelectedItem.value;
    string text=DropDownList1.SelectedItem.Text;
      

  2.   

    DropDownList is three property:DataTextField and DataValueField and DataSource
    You can set DataSource and set other property will ok!
    You havnt need ArrayLis!
    this two property is field in table of the database !
    你只要榜定两个数据库中的字段就可以了!一帮情况下榜定一个ID和一个Caption就可以了!
      

  3.   

    1.可以直接用DataReader
    2.可以直接用DataSet
    3.可以直接用DataView
      

  4.   

    可以将DropDownList1.DataTextField="name";
          DropDwonList1.DataValueField="id";
    的数值设置成一样吗?我的程序如下:
    Source = new SqlConnection("data source=CYT;initial catalog=TK;persist security info=True;user id=sa;workstat" +
    "ion id=CYT;packet size=4096");
    Source.Open();
    DataSet DS = new DataSet();
    SqlDataAdapter NComm = new SqlDataAdapter(d, Source);
    NComm.Fill(DS, "staff");
    //Session["NowDS"]=DS;//宣告为Session
    a.DataSource=DS.Tables["staff"].DefaultView;
    a.DataTextField="JLR_NAME";
    a.DataValueField="JLR_KIND";
    a.DataBind();
    private void Button1_Click(object sender, System.EventArgs e)
    {
    b.Text=a.SelectedItem.Text;
    }但是按按钮后,文本框b的数值一直保持a中默认的第一个值!!!、????而且a中的值也自动变回默认的第一个值!
      

  5.   

    b.Text=a.SelectedItem.Text;
    这句的意思是获得a中索引值最小的值的TEXT阿!!!!有谁知道应该怎样做阿?
      

  6.   

    可以将DropDownList1.DataTextField="name";
          DropDwonList1.DataValueField="id";
    的数值设置成一样吗?可以
      

  7.   

    Source = new SqlConnection("data source=CYT;initial catalog=TK;persist security info=True;user id=sa;workstat" +
    "ion id=CYT;packet size=4096");
    Source.Open();
    DataSet DS = new DataSet();
    SqlDataAdapter NComm = new SqlDataAdapter(d, Source);
    NComm.Fill(DS, "staff");
    //Session["NowDS"]=DS;//宣告为Session
    a.DataSource=DS.Tables["staff"].DefaultView;
    a.DataTextField="JLR_NAME";
    a.DataValueField="JLR_KIND";
    a.DataBind();
    放到
    if(!Page.IsPostBack)
    {
      .........
    }
    里面
      

  8.   

    Dim i As Integer
            Dim arr(4, 2)
            arr(0, 0) = "x"
            arr(0, 1) = "1"
            arr(1, 0) = "xx"
            arr(1, 1) = "2"
            arr(2, 0) = "xxx"
            arr(2, 1) = "3"
            arr(3, 0) = "xxxx"
            arr(3, 1) = "4"
            For i = 0 To 3
                DDL.Items.Add(New ListItem(arr(i, 0), arr(i, 1)))
            Next