SelectedIndex是一个索引值,不可以与类别的id号关联的比如Id | Nclass
|
5 | 国内
10 | 国外
19 | 工业 在修改一个 id 号是10 的一个新闻时,此时他的DropDownList1.SelectedIndex=1 如何根据他的id=10 来只能让他的选定值为国外?
|
5 | 国内
10 | 国外
19 | 工业 在修改一个 id 号是10 的一个新闻时,此时他的DropDownList1.SelectedIndex=1 如何根据他的id=10 来只能让他的选定值为国外?
id=10;
for(int i=0;i<DropDownList1.Items.Count;i++)
{
if(DropDownList1.Items[i].Value==id)
{
DropDownList1.SelectedIndex=i;
break;
}
}
用的时DropDownList的 Value的属性,
不是 Text
你们提供的方法 出现如下错误:
System.NullReferenceException: 未将对象引用设置到对象的实例。