DropDownList.SelectedValue resets inadvertently

G

Guest

I have a strange issue:
I have a dropdownlist (lstSrchPeriod) that has a SelectedValue of something
(say "12"). I use an IF statement to determine if that value is there:
If lstSrchPeriod.SelectedValue <> "0" Then
theWhere &= " AND rpt_period = '" &
lstSrchPeriod.SelectedValue & "'"
End If
....that works fine. Then I evaluate this next DropDownList...
If lstSrchCenter.SelectedValue <> "0" Then
theWhere &= " AND center_id = " & lstSrchCenter.SelectedValue
End If
....and when it evaluates the IF statement, it resets
lstSrchPeriod.SelectedValue to "0". I have stepped through it and no code is
run that would reset this. I have
no idea what is happening.

Do any of you have an idea about this?
Don DeVeux
 
G

Guest

Well, I solve my own problem - but maybe this will keep someone else from
making the same mistake.

When I defined the values for these 2 DropDownLists, I also defined a ListItem
Dim li As ListItem
.... I defined this object as...
li = New ListItem("No Selection", 0)
....and used inserted it into each of the DropDownLists
lstSrchPeriod.Items.Insert(0, li)
lstSrchCenter.Items.Insert(0, li)

This seems to create a conflict in these objects. I fixed this problem by
creating a second ListItem object and using that to fill the second DDL, like
this...
Dim li As ListItem, li1 As ListItem
li = New ListItem("No Selection", 0)
lstSrchPeriod.Items.Insert(0, li)
li1 = New ListItem("No Selection", 0)
lstSrchCenter.Items.Insert(0, li1)

This seems like a bug to me and I will report it to MS.

Don DeVeux
 
A

Asela Gunawardena

have checked for ispostpack during page load this also makes the values
reset when the autopostback is set to true.
 
G

Guest

Yes - I am aware of the IsPostBack issue, but that wasn't the problem this
time. Thanks for your response. I did find the solution later (see below).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top