如题:想从数据库中读出数据到控件中 使得控件当前显示的是读取出来的值...

解决方案 »

  1.   

    public void BindDDl()
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            con.Open();
            cmd.CommandText = "select BookName,BookID from movieTable";
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            DataSet ds = new DataSet();
            sda.Fill(ds, "book");
            this.DropDownList1.DataSource = ds.Tables["book"];   
            this.DropDownList1.DataTextField = "BookName";
            this.DropDownList1.DataValueField = "BookId";
            this.DropDownList1.DataBind();
            cmd.Dispose();
            con.Close();
        }
      

  2.   

    楼上就可以了,还可以用foreach或for来赋值。
      

  3.   

    选择好的入门参考可以培养好的编程味道。推荐先读网上的:http://www.google.cn/search?complete=1&hl=zh-CN&rlz=1T4GGLS_zh-CNCN263CN263&q=scott+mitchell+asp.net2.0&meta=lr%3Dlang_zh-CN%7Clang_zh-TW&aq=f