dropdownlist - cast value as integer

Posted on 2008-10-06
Last Modified: 2012-05-05
I have a dropdownlist below--

In the event handler...i want to assign the value to this:

 Locales.CurrentLocaleId = ddlLocale.SelectedItem.Value;

But  Locales.CurrentLocaleId is integer. I tried (int) ddlLocale.SelectedItem.Value;
but that didnt work can I do this?
<asp:DropDownList ID="ddlLocale" runat="server" 
                    <asp:ListItem Value="1033" Text="Ebglish" Selected="True"></asp:ListItem>
                    <asp:ListItem Value="1031" Text="German" ></asp:ListItem>

Open in new window

Question by:Camillia
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 96

Accepted Solution

Bob Learned earned 500 total points
ID: 22650632
Try int.Parse(ddlLocale.SelectedValue.ToString)

Author Comment

ID: 22650765
that worked ( had to do ToString() )...

but howcome (int) dlllocale.selectedvalue.tostring(); didnt work?

why do I need to add "Parse" it because C# wont allow conversion between int and string/
LVL 96

Expert Comment

by:Bob Learned
ID: 22650985
You can't cast from a string to an int that way.  If you are looking for a reason, I don't think that I can give you one.  I just rely on the fact that the compiler complains about it.

Author Comment

ID: 22651162

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question