您的位置:首页 > 移动开发 > Objective-C

用DropDownList+ObjectDataSource在Page_Load中SelectedIndex和SelectedValue的区别

2007-10-19 15:52 459 查看
最近在调试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="默认值"可以设置成功!

对于具体的原因还没完全理解,先搁着了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: