[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Problem with case not returning correct results

Hi
can anyone help with this problem
When using the case statement the code is returning the value not the text.
Code below.

<script runat="server">
void Page_Load(Object Src, EventArgs E)
{
DisplayCountry.Text = Session["CRCountry"].ToString();
switch(DisplayCountry.ToString())
{
case "1000":
DisplayCountry.Text ="Afghanistan";
break;
more case blocks
}
}
</script>
<asp:Label ID="DisplayCountry" runat="server"/>

Instead of returning the country name, it returns the value from the session.
Any help would be appreciated
Caz


0
BeginningWebDesign
Asked:
BeginningWebDesign
  • 3
  • 2
1 Solution
 
hongjunCommented:
Perhaps none of the case condition is satisfied.
Maybe you need a default in case none of the case condition fit.

case "1000":
    //
...
default:
    // here
0
 
BeginningWebDesignAuthor Commented:
Hi hongjun

1000 is a valid case

Regards
Caz
0
 
hongjunCommented:
have you tried displaying the value?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BeginningWebDesignAuthor Commented:
yes it displays 1000
0
 
ihenryCommented:
I think it should be like this

switch(DisplayCountry.Text.ToString())
{
  ...
  ...
0
 
BeginningWebDesignAuthor Commented:
Thanks ihenry

That solved the problem

Caz
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now