DropDownList的数据源是Web.Config

首先在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>

             注:该代码一定要在<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)));
        }
原文地址:https://www.cnblogs.com/xbf321/p/896053.html