私はこれがあなたのためにそれをするべきだと思う...
これはあなたのweb.configにあります...
<configSections>
<section name="DataBaseKeys" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<DataBaseKeys>
<!--Connection Strings for databases (or IP Addresses or whatever)-->
<add key="dbCon1" value="Data Source=DbServerPath;Integrated Security=True;database=DbName1"/>
<add key="dbCon2" value="Data Source=DbServerPath;Integrated Security=True;database=DbName1"/>
<add key="dbCon3" value="Data Source=DbServerPath;Integrated Security=True;database=DbName1"/>
<add key="dbCon4" value="Data Source=DbServerPath;Integrated Security=True;database=DbName1"/>
<add key="dbCon5" value="Data Source=DbServerPath;Integrated Security=True;database=DbName1"/>
</DataBaseKeys>
これはあなたのコードです...
using System.Configuration;
using System.Collections.Specialized;
protected void Page_Load(object sender, EventArgs e)
{
LoadDdls();
}
private void LoadDdls()
{
NameValueCollection nvcDbKeys = GetDbKeys();
//Loop through the collection
for (int i = 0; i < nvcDbKeys.Count; i++)
{
// "Keys" is the "key" - Get(int) is the "value"
this.DropDownList1.Items.Add(new ListItem(nvcDbKeys.Keys[i], nvcDbKeys.Get(i)));
}
}
private NameValueCollection GetDbKeys()
{
//Declare a name value collection to store Database Key List from web.config
NameValueCollection nvcDatabaseKeyList;
nvcDatabaseKeyList = (NameValueCollection) ConfigurationManager.GetSection("DataBaseKeys");
return nvcDatabaseKeyList;
}