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
  • 2
  • 2
LVL 96

Accepted Solution

Bob Learned earned 500 total points
Comment Utility
Try int.Parse(ddlLocale.SelectedValue.ToString)

Author Comment

Comment Utility
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
Comment Utility
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

Comment Utility

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Put text in a picture ASP.NET C# 2 35
Windows Service with UDP 2 26
Duplicate a row 2 29
Chat Room 1 25
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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now