现在的位置: 首页 > 综合 > 正文

DropDownList比较好的设置值的方式

2012年09月17日 ⁄ 综合 ⁄ 共 148字 ⁄ 字号 评论关闭

DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(xxx));
通过FindByValue没有找到指定项返回值为null,而Items.IndexOf(null)会返回-1

抱歉!评论已关闭.