dropdownlist直接绑定数据库中字段数据....但当dropdownlist已经绑定好数据后,再怎么设置默认显示项??
protected void dropdownlist_SelectedIndexChanged(object sender,EventArgs e)
{
if(this.dropdownlist.SelectedValue!="0")
{
获取到的数据集(eg:ArrayList teacherList = BusinessFacade.glb_TeacherList(QueryParam qp, out RocordCount2);)
this.dropdownlist.DataSource=list;
this.dropdownlist.DataTextField="数据库中字段";
this.dropdownlist.DataValueField="数据库中字段";
this.dropdownlist.DataBind();
this.dropdownlist.Items.Insert(0,new System.Web.UI.WebControls.ListItem("请选择","0"));
this.dropdownlist.Visible=true;
}
}
protected void Page_Load(object sender, EventArgs e)
{
//当从一个页面传过来一个值,这个值在dropdownlist绑定的数据中,就可以这样来设置默认显示项为传过来的那个值...
if(!ispostback)
{
ddlstuname.Items.FindByText(student.RealityName).Selected = true;
}
}

浙公网安备 33010602011771号