.NET中ListBox和DropDownList的数据绑定
private void Button1_Click(object sender, System.EventArgs e)
{
if(ListBox1.Visible==false)
{
SqlConnection conn=new SqlConnection(@"Server="+DB_Host+";DataBase="+DB_Name+";uid="+DB_Uid+";pwd="+DB_Pwd+"");
SqlDataAdapter da=new SqlDataAdapter("SELECT * from TEMP",conn);
DataSet ds=new DataSet();
da.Fill(ds,"UN");
ListBox1.DataSource=ds;
ListBox1.DataTextField="UN";
ListBox1.DataValueField="UP";
ListBox1.DataBind();
ListBox1.Visible=true;
}
else
{
ListBox1.Visible=false;
}
}