string strconn=ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection con=new SqlConnection(strconn);
con.Open();//建立链接完毕
SqlCommand com=new SqlCommand("select * from attend",con);
SqlDataReader sdr=com.ExecuteReader();
this.DDL_manufacturer.DataSource=sdr;
this.DDL_manufacturer.DataTextField="manufacturer";//要显示的字段
this.DDL_manufacturer.DataValueField="attendid";//设置主键
this.DDL_manufacturer.DataBind();
这是我用的代码 默认的就是第一项
if(dropdownlist.Items.Count>0)
{
dropdownlist.SelectedIndex=0;
}
else
{
dropdownlist.SelectedIndex=-1;
}
dropdownlist.SelectedIndex=0;
dropdownlist.item[0].selected=true
或是: dropdownlist.SelectedIndex=0;
都可以啊
判断一下还是好的啊