Implementing a dynamic drop down list box in a web form control in C#

Posted on 2004-11-26
Last Modified: 2008-02-26
Dear Expert,
   I am developing a web form in C# which has a drop down list box that contains units of measure, i.e. in, ft, mm, m, and km. I have set the selected value to inch. Here is the scenario. Say the end user enters a value of 10 inside the corresponding text box. When the end user changes units to any other unit like mm the conversion works fine, showing the value 254 mm. How do I make this flexible so that if the end user decides to select a unit of measure for example mm, but doesn't want the converted mm value, which in this case is 10 inches, instead the end user wants to override the converted value  25 mm by changing the textbox value. If the end user wants to convert this newly entered value to say meters, it should just be a matter of selecting that from the drop down list box and displaying the value .025 m.
  I guess my question would be how do I keep track of the previous selected value at the same time keeping track of the newly selected value to provide for the correct conversion.


Question by:Khopkins32
    LVL 53

    Accepted Solution

    Just keep the last selectedIndex in a hidden input.  Then pass the old value from the hidden field and the new index value to the calculation function:

    <input type="hidden" name="last" value="0">
    <input type="text" name="Userin">


    Author Comment

    Thanks vervy much Coboldinosaur
    LVL 53

    Expert Comment

    Glad I could help.  Thanks for the A. :^)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Building “do-it-yourself” web sites has become an epidemic. There are so many blogs, web sites and even books that "teach" you how to build your web site in a few extremely simple and easy steps. Building a web site has become easier than boiling an…
    Read about why website design really matters in today's demanding market.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now