dropdownlist绑定

来源:互联网 发布:演唱会门票 知乎 编辑:程序博客网 时间:2024/04/28 17:32
protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection myconnection = new SqlConnection("server=(local);database=Northwind;uid=sa;pwd=");
        string sql = "select categoryName from categories";
        SqlDataAdapter sda = new SqlDataAdapter(sql,myconnection);
        DataSet ds = new DataSet();
        sda.Fill(ds,"a");
        DropDownList1.DataSource = ds.Tables["a"];
        DropDownList1.DataTextField = "categoryName";
        DropDownList1.DataBind();