【发布时间】:2011-06-29 20:19:32
【问题描述】:
我的 appSetting 块看起来像这样:
<appSettings>
<key="site1" value="http://www.thissite.com,site name" />
<key="site2" value="http://www.thissite.com,site name" />
</appSettings>
我想用值和文本填充下拉列表:
value="http://www.thissite.com" text="网站名称"
我可以使用以下方法将它们放入单独的数组中:
string[] mykey = ConfigurationManager.AppSettings["site1"].Split(',');
string[] mykey = ConfigurationManager.AppSettings["site2"].Split(',');
但是,我想将它们组合成一个数组,然后循环并填充代码隐藏中的下拉列表。我可以通过这种方式循环遍历各个数组来填充它,但似乎必须有更好的方法,代码更少。
谁能告诉我怎么做?
感谢下面的acermate433s' answer。
NameValueCollection appSettings = ConfigurationManager.AppSettings;
for (int i = 0; i < appSettings.Count; i++)
{
Response.Write(appSettings.GetKey(i).ToString() + "-" + appSettings[i].ToString());
}
显然,我会做的不仅仅是展示它。
【问题讨论】: