DropDownList selectedIndex is not updated

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wanda

    DropDownList selectedIndex is not updated

    Hi,

    I am trying to read the DropDownList's selectedIndex when it fires the
    event
    "SelectedIndexC hanged", however, the index value is always 0 no matter
    what I've clicked. I just wonder what have I done wrong in my code...

    This is how I populate my list at the Page_Load!!!!


    Dim myCMD As SqlCommand = New SqlCommand(strS QL, cn)
    Dim myReader As SqlDataReader = myCMD.ExecuteRe ader()
    Dim fNextResult As Boolean = True

    lstEmployee.Ite ms.Clear()
    Do Until Not fNextResult
    Do While myReader.Read()
    If Not myReader.IsDBNu ll(0) Then
    lstEmployee.Ite ms.Add(New
    ListItem(myRead er.GetString(1) , myReader.GetInt 32(0)))
    End If
    Loop
    fNextResult = myReader.NextRe sult()
    Loop
    myReader.Close( )


    Thanks in advance. Any help will be greatly appreciated.
    Wanda
  • Karl

    #2
    Re: DropDownList selectedIndex is not updated

    Assume from potential readiability problems with the code, make sure it's
    wrapped in an:

    If Not Page.IsPostBack Then
    ... 'put your code in here
    end if

    Otherwise, on postback, your ddl is repopulated and its selected value lost.

    Karl


    "Wanda" <wandali@rogers .com> wrote in message
    news:11ac19d1.0 408301029.76c6a 6b8@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > I am trying to read the DropDownList's selectedIndex when it fires the
    > event
    > "SelectedIndexC hanged", however, the index value is always 0 no matter
    > what I've clicked. I just wonder what have I done wrong in my code...
    >
    > This is how I populate my list at the Page_Load!!!!
    >
    >
    > Dim myCMD As SqlCommand = New SqlCommand(strS QL, cn)
    > Dim myReader As SqlDataReader = myCMD.ExecuteRe ader()
    > Dim fNextResult As Boolean = True
    >
    > lstEmployee.Ite ms.Clear()
    > Do Until Not fNextResult
    > Do While myReader.Read()
    > If Not myReader.IsDBNu ll(0) Then
    > lstEmployee.Ite ms.Add(New
    > ListItem(myRead er.GetString(1) , myReader.GetInt 32(0)))
    > End If
    > Loop
    > fNextResult = myReader.NextRe sult()
    > Loop
    > myReader.Close( )
    >
    >
    > Thanks in advance. Any help will be greatly appreciated.
    > Wanda[/color]


    Comment

    Working...