Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


dropdownlist - cast value as integer

Posted on 2008-10-06
Medium Priority
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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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