protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
binddata();
}
//这里一定要注意了,我开始没注意折腾我两小时。
//DropDownList的AutoPostBack属性一定设定的是为True,所以在改变DropDownList的选项时会刷新页面,导致的DropDownList重新绑定。
//如果你的DropDownList不会触发SelectedIndexChanged事件的话,将AutoPostBack属性改为False就可以了。}
public void binddata()
{
DataSet ds = new DataSet();
StringBuilder strWhere = new StringBuilder();
ds = bll.GetList(strWhere.ToString());
DropDownList1.DataSource = ds.Tables[0].DefaultView ;
DropDownList1.DataTextField = "name"; //DropDownList 控件的文本域
DropDownList1.DataValueField = "ID";//DropDownList 控件的数值域
DropDownList1.DataBind();
//DropDownList1.Items.Insert(0, new ListItem("----请选择部门----", "----请选择部门---- "));
//这里根据个人的需求添加
}