首先在Web.Config添加以下代码;
<configSections>
<section name="interfaceStyle" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<interfaceStyle>
<add key="Window" value="Window"></add>
<add key="Xp" value="Xp"></add>
</interfaceStyle>
<section name="interfaceStyle" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<interfaceStyle>
<add key="Window" value="Window"></add>
<add key="Xp" value="Xp"></add>
</interfaceStyle>
注:该代码一定要在<Configration>下的第一行
如果想添加更多的列表,就<add key="" value="" />
然后是调用:
NameValueCollection nvc = (NameValueCollection)ConfigurationManager.GetSection("interfaceStyle");
for (int i = 0; i < nvc.Count; i++ )
{
this.DropDownList1.Items.Add(new ListItem(nvc[nvc.GetKey(i)],nvc.GetKey(i)));
}
for (int i = 0; i < nvc.Count; i++ )
{
this.DropDownList1.Items.Add(new ListItem(nvc[nvc.GetKey(i)],nvc.GetKey(i)));
}