#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Red face Populate a Dropdown list based on another one in VB.NET


    Hi

    I want to be able to populate a drop down list based on the selection of another one or others using vb.net and also pass the value selected to another page or within the same page. for instance one drop down to select a country and a second one to populate the cities based on the first selection. I added one in the code below one below so need to add another one and populate it based on the selection in the first one. I am not using a Database. I just want the selection from the list as it is added manually.. Can you please advise of an example on how to achieve this or help exapand the code below . Thanks

    Code:
           <Script Runat="Server">
    Sub Button_Click( s As Object, e As EventArgs )
    if IsValid then  
    response.redirect ("test.aspx?id=" & countries.Text & " ")
    end if
    end sub
    </script>
    
        Select a Country <asp:DropDownList ID="countries" runat="server"
        AppendDataBoundItems="true">
        <asp:ListItem>France</asp:ListItem>
         <asp:ListItem>Spain</asp:ListItem>
          <asp:ListItem>USA</asp:ListItem>
           <asp:ListItem>Italy</asp:ListItem>
          <asp:ListItem>England</asp:ListItem>
         </asp:DropDownList>
    
        <asp:Button ID="Button1" runat="server" Text="Search..." onclick="Button_Click" />
        </form>
  2. #2
  3. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    Hello! I've added [code] tags to your code. They help to preserve formatting and prevent emoticons from popping up mid-code. Please use them in the future when you post code
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2016
    Posts
    54
    Rep Power
    2
    you need to use javascript, to generate the second dropdown list. or at least, to generate the option via javascript.

    so when "onclick" is called, you simply generate the content in the javascript function named "Button_Click".
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2016
    Posts
    54
    Rep Power
    2
    Or, you could post the click to the server, and generate an new page with the second list added, that does seem a bit overkill however....

IMN logo majestic logo threadwatch logo seochat tools logo