Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 3rd, 2003, 07:56 PM
Registered User
Join Date: Jun 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Title: dropdown list as selected according to the

<script language="VB" runat="server">
Sub btnsubmit(Src As Object, E As EventArgs)
    if countryname.text="USA" then
     end if

End Sub

<form runat="server">
Please enter country Name:<asp:textbox id="countryname" runat="server"/>


You selected the country<asp:dropdownlist id="country" runat="server">
              <asp:listitem >USA</asp:listitem>

              more countries name in dropdown list.

         <asp:button text="submit" id="btn" onclick="btnsubmit" runat="server" />



if the person enters USA in the testbox and clicks the submit button then the USA should come as selected.
the code i've written above works perfectly. but if i had to do it for 50 countries then there would be about 50 if statements.
is there any other methods to do it.
Can i not do it by the value of the string that is entered in the textbox and match the string in the dropdownlist to bring it as selected item.

can you please write the code.

much much thanks if you can help me.
Old June 4th, 2003, 01:55 AM
Registered User
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Just set ViewState=true on your dropdownlist property

<asp:dropdownlist ... EnableViewState="True">

If you by any point in time decides to fill in the dropdownlist property programmaticly, remember to only do so one time:

    your code

else your selection will be overridden when the OnPageLoad event fires (the classic "my selection isnt remembered" mistake;)).

Anders R

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to highlight selected dropdown values. sheetm J2EE 0 June 5th, 2007 05:04 AM
Selected value from dropdown menu wont display. mizjinx Classic ASP Databases 0 May 20th, 2007 08:24 PM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
Reloading page when option selected in dropdown chandrasekhar200 Beginning PHP 1 March 10th, 2006 04:52 AM
Getting selected item in dropdown to match XML juliaPGATOUR XSLT 1 December 11th, 2003 05:56 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.