473,394 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DropDownList.SelectedValue resets inadvertently

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
Dec 21 '05 #1
3 1527
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
"rengeek33" wrote:
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

Dec 21 '05 #2
have checked for ispostpack during page load this also makes the values
reset when the autopostback is set to true.
"rengeek33" <re*******@nospamhere.com> wrote in message
news:1F**********************************@microsof t.com...
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
"rengeek33" wrote:
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

Dec 22 '05 #3
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).

"Asela Gunawardena" wrote:
have checked for ispostpack during page load this also makes the values
reset when the autopostback is set to true.
"rengeek33" <re*******@nospamhere.com> wrote in message
news:1F**********************************@microsof t.com...
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
"rengeek33" wrote:
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


Dec 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
15
by: Swetha | last post by:
Hello I have a DropDownList that I am populating using the following SqlDataSource: <asp:DropDownList ID="parentIDDropDownList" runat="server" DataSourceID="SqlDataSource3"...
3
by: Carlos Lozano | last post by:
Hello, I am having a problem getting the selectedValue from a dropdownlist that is populated with a dataReader and just can't see the problem. I did the following: dim dr as DataReader dr...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
by: =?Utf-8?B?ZGVuIDIwMDU=?= | last post by:
Hi, Trouble in retaining values of dropdownlist, textboxes, and other controls when dropdownlist selectedindexchanged event is triggered, the controls are inside a user control and this user...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
1
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.