Elegabalus
Programmer
I'm using the Visual Studio 2005 Beta 2 build, but this should be the same across different versions.
I'm trying to use a Switch/Case statement to determine which label should be displayed.
I've got several keys stored in the web.config file that I want to use as the comparison for the switch statement. However, I get an error saying that "A constant value is expected." I understand that you can't have variables in the switch statement, but you can't have a fixed value from the config file?
Here's some code:
Anyone have an idea how to get this to work?
I'm trying to use a Switch/Case statement to determine which label should be displayed.
I've got several keys stored in the web.config file that I want to use as the comparison for the switch statement. However, I get an error saying that "A constant value is expected." I understand that you can't have variables in the switch statement, but you can't have a fixed value from the config file?
Here's some code:
Code:
switch (strID)
{
case ConfigurationManager.AppSettings["ID1"].ToString():
Label1.Visible = true;
break;
case ConfigurationManager.AppSettings["ID2"].ToString():
Label2.Visible = true;
break;
case ConfigurationManager.AppSettings["ID3"].ToString():
Label3.Visible = true;
break;
default:
Label1.Visible = true;
break;
}
Anyone have an idea how to get this to work?