dropdownlist如何选中第一项的值

2025-02-28 15:36:40
推荐回答(5个)
回答1:

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();

这是我用的代码 默认的就是第一项

回答2:

if(dropdownlist.Items.Count>0)
{
dropdownlist.SelectedIndex=0;
}
else
{
dropdownlist.SelectedIndex=-1;
}

回答3:

dropdownlist.SelectedIndex=0;

回答4:

dropdownlist.item[0].selected=true
或是: dropdownlist.SelectedIndex=0;
都可以啊

回答5:

判断一下还是好的啊