Solved

dropdownlist - cast value as integer

Posted on 2008-10-06
4
765 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
Comment Utility
Try int.Parse(ddlLocale.SelectedValue.ToString)
0
 
LVL 7

Author Comment

by:Camillia
Comment Utility
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
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.
0
 
LVL 7

Author Comment

by:Camillia
Comment Utility
thanks.
0

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 (http://www.enterprise.efax.com), 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