Dropdown list - SelectedIndexChanged event doesn't fire

Discussion in 'ASP .Net' started by =?Utf-8?B?SmFjaw==?=, Mar 14, 2005.

  1. Hello,

    I have a dropdown list on a user control and the AutoPostBack property is
    set to True. I want to use the SelectedIndexChanged event to populate some
    text boxes based on what the user chose in the dropdown list.

    However, the SelectedIndexChanged event doesn't fire. In the immediate
    window it appears that the index is not changing when I select a different
    option in the list.

    After wrestling with this for a couple hours, I think it has to do with the
    fact that I am loading the list options from the database:

    sql = "SELECT Code, Description FROM luApptType"
    ds = clsDB.GetDataSet(sql)
    With Me.lstApptType
    .DataSource = ds
    .DataTextField = "Description"
    .DataValueField = "Code"
    .DataBind()
    .Items().Insert(0, New ListItem(""))
    End With

    The code above is contained in a LoadLists function that is called in the
    first Page Load:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    LoadLists()
    End If
    End Sub

    When I try this with a second dropdown where the options are hard-coded, the
    SelectedIndexChanged event fires as expected. No problems.

    Can you tell me why it's not working with the first dropdown where the
    options are loaded at runtime?

    Thanks -- I'm at my wit's end!
    =?Utf-8?B?SmFjaw==?=, Mar 14, 2005
    #1
    1. Advertising

  2. Please disregard my earlier post. I had a coworker take a look at it, and on
    the first run-through, it magically started working.

    "Jack" wrote:

    > Hello,
    >
    > I have a dropdown list on a user control and the AutoPostBack property is
    > set to True. I want to use the SelectedIndexChanged event to populate some
    > text boxes based on what the user chose in the dropdown list.
    >
    > However, the SelectedIndexChanged event doesn't fire. In the immediate
    > window it appears that the index is not changing when I select a different
    > option in the list.
    >
    > After wrestling with this for a couple hours, I think it has to do with the
    > fact that I am loading the list options from the database:
    >
    > sql = "SELECT Code, Description FROM luApptType"
    > ds = clsDB.GetDataSet(sql)
    > With Me.lstApptType
    > .DataSource = ds
    > .DataTextField = "Description"
    > .DataValueField = "Code"
    > .DataBind()
    > .Items().Insert(0, New ListItem(""))
    > End With
    >
    > The code above is contained in a LoadLists function that is called in the
    > first Page Load:
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > If Not IsPostBack Then
    > LoadLists()
    > End If
    > End Sub
    >
    > When I try this with a second dropdown where the options are hard-coded, the
    > SelectedIndexChanged event fires as expected. No problems.
    >
    > Can you tell me why it's not working with the first dropdown where the
    > options are loaded at runtime?
    >
    > Thanks -- I'm at my wit's end!
    >
    >
    >
    =?Utf-8?B?SmFjaw==?=, Mar 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CW
    Replies:
    2
    Views:
    7,031
  2. john
    Replies:
    0
    Views:
    356
  3. john
    Replies:
    0
    Views:
    319
  4. Replies:
    1
    Views:
    7,961
    =?Utf-8?B?Um9iZXJ0IEJ1cmRpY2sgW2VNVlBd?=
    Oct 27, 2005
  5. akhzar
    Replies:
    1
    Views:
    719
    akhzar
    Mar 6, 2009
Loading...

Share This Page