Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String array in web.config? 1

Status
Not open for further replies.

graabein

Programmer
Oct 9, 2002
186
NO
Hi, I have a couple dropdowns I want to configure from Web.config instead of using a database backend. I have done this by key-value pairs in appSettings of Web.config.

Is there any way to add arrays? I guess I could do a <add key="listName" value="value1, value2, value3" /> and parse the string...

BTW how do I parse a comma separated string as string[] or ArrayList?

[elephant2]
graabein
 
Thanks, I got it to work. Here is what I did.
Code:
string[] listValues = ConfigurationSettings.AppSettings["listName"].Split(',');
foreach (string listValue in listValues)
{
    dropdown.Items.Add(new ListItem(listValue));
}

Notice the Web.config setting had to lose the whitespace between values.
Code:
<add key="listName" value="value1,value2,value3" />

Looks much cleaner now!
 
Notice the Web.config setting had to lose the whitespace between values.
Another way would be to use the Trim method before adding the values to the DropDownList.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top