Results 1 to 5 of 5

Thread: [RESOLVED] dropdownlist SelectionChange

  1. #1

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Resolved [RESOLVED] dropdownlist SelectionChange

    I have some constant arraylists that are filled when a dropdownlist value is changed (based on the value of the DDL). When the first DDL is changed, I have a second DDL that binds to the values of the constant arraylist. However I ran the code and change the value of the ddl but it doesn't databind to the second DDL. Do I have to refresh the page? And if so how can I tell it to keep the selectedvalue of the first dropdownlist that was fires the SelectedIndexChanged event?

    VB Code:
    1. Private Sub ddlSection_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSection.SelectedIndexChanged
    2.         If ddlSection.SelectedItem.Text = "500" Then 'this is the first ddl
    3.             'Section500
    4.             arrSection500.Clear()
    5.             arrSection500.Add("Select Form")
    6.             arrSection500.Add("500-10")
    7.             arrSection500.Add("500-10C")
    8.             arrSection500.Add("500-11")
    9.  
    10.             ddlForm.DataSource = arrSection500 'this is the second ddl i want to bind this arraylist to
    11.             ddlForm.DataBind()
    12.         End If

    THanks again!!
    Last edited by drpcken; Oct 21st, 2005 at 05:55 PM.

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: dropdownlist SelectionChange

    I write in C#, not VB, so the code is slightly different, but my event contains the following code and executes perfectly:

    VB Code:
    1. System.Collections.ArrayList oAL = new ArrayList(0);
    2.             oAL.Add("== Please Choose ==");
    3.             oAL.Add("500-10");
    4.             oAL.Add("500-10C");
    5.             oAL.Add("500-11");
    6.  
    7.             ddlForm.DataSource = oAL;
    8.             ddlForm.DataBind();
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  3. #3

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: dropdownlist SelectionChange

    aah thanks!

    another problem I'm having is I need my dropdownlist to be the value of a parameter in the url if the parameter exists, but it doesn't seem to work. Here's my code

    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         'Put user code to initialize the page here
    3.         If Not IsPostBack Then
    4.             If Request.QueryString("section") = "" Then
    5.                 ddlSection.SelectedIndex = -1
    6.             Else
    7.                 ddlSection.SelectedItem.Value = Request.QueryString("section")
    8.             End If
    9.         End If
    10.     End Sub

    Right now when the parameter equals something, my ddl still goes to my default value and not my value of my parameter.

  4. #4
    New Member leparduk's Avatar
    Join Date
    Oct 2005
    Posts
    7

    Re: dropdownlist SelectionChange

    foreach x as listitem in ddlSection.items
    if x.Value = Request.QueryString("section") then
    x.selected=true
    exit for
    endif
    next
    Just because you're paranoid doesn't mean they aren't out to get you

    Quidquid latine dictum sit, altum viditur

  5. #5

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: dropdownlist SelectionChange

    Thanks for the suggestion, what I did though was set AUTOPOSTBACK on and when it loads it grabs its value i was setting the parameter as from a different control

    Thanks for all the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width