Solved

dropdownlist - cast value as integer

Posted on 2008-10-06
4
775 Views
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 either...how can I do this?
<asp:DropDownList ID="ddlLocale" runat="server" 
                    onselectedindexchanged="ddlLocale_SelectedIndexChanged">
                    <asp:ListItem Value="1033" Text="Ebglish" Selected="True"></asp:ListItem>
                    <asp:ListItem Value="1031" Text="German" ></asp:ListItem>
                </asp:DropDownList>

Open in new window

0
Comment
Question by:Camillia
  • 2
  • 2
4 Comments
 
LVL 96

Accepted Solution

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

Author Comment

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

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

why do I need to add "Parse"..is it because C# wont allow conversion between int and string/
0
 
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.
0
 
LVL 7

Author Comment

by:Camillia
ID: 22651162
thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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