
Code
1 SqlConnection conn = new SqlConnection("server=.;uid=sa;database=pubs");
2 SqlDataAdapter dap = new SqlDataAdapter("select * from jobs", conn);
3 DataTable dt = new DataTable();
4 dap.Fill(dt);
5 DropDownList1.Items.Clear();
6 DropDownList1.DataSource = dt;
7 DropDownList1.DataTextField = "job_desc";
8 DropDownList1.DataValueField = "job_id";
9 DropDownList1.DataBind();
10 DropDownList1.Items.Insert(0, new ListItem("", ""));//插入空项,此举必须放到数据绑定之后
11