最近在調試ASPx頁面時發現了用DropDownList+ObjectDataSource在Page_Load中用DropDownList.SelectedValue="默認值",當默認值不存在列表中時會出錯,在網上搜索了別人的經驗後使用DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByValue("默認值"));避免了錯誤,但是發現在Page_Load中設置失敗,原因:The data binding will be done after the page_load was called, so if you were trying to set the selected value in the page load it will fail. You need to use the DataBound event, where the data will be already binded to the drop downlist.這個原因了解了,可是只要“默認值”是在列表中,用DropDownList.SelectedValue="默認值"可以設置成功!
對於具體的原因還沒完全理解,先擱著了。