473,414 Members | 1,947 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,414 software developers and data experts.

Determining whether a DropDownList has changed...

I have a problem that I figured would be relatively common, but have
been unable to find any information on it as of yet. I have a page
that contains two DropDownList controls, with the second being
dependent on the value of the first. My DropDownList control
definitions look like this:

<asp:dropdownlist id="ddlLocCty" runat="server" CssClass="SmlBox"
AutoPostback="True" CausesValidation="False"></asp:dropdownlist>

<asp:dropdownlist id="ddlLocOfce" runat="server"
CssClass="SmlBox"></asp:dropdownlist>

When the first list is changed, the second list is rebuilt based on
the selection of the first. My code-behind looks like this:

....
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
bind_ddlLocCty()
bind_ddlLocOfce()
bind_ddlReqType()
bind_ddlReqStat()
End If
End Sub

....

Private Sub bind_ddlLocCty()
ddlLocCty.DataSource = BindCty()
ddlLocCty.DataValueField = "cty_cd"
ddlLocCty.DataTextField = "cty_nme_txt"
ddlLocCty.DataBind()
ddlLocCty.Items.Insert(0, New ListItem(" ", ""))
End Sub

Private Sub bind_ddlLocOfce()
ddlLocOfce.DataSource = BindOfce()
ddlLocOfce.DataValueField = "ofce_nbr"
ddlLocOfce.DataTextField = "ofce_txt"
ddlLocOfce.DataBind()
ddlLocOfce.Items.Insert(0, New ListItem(" ", ""))
End Sub

....

Function BindCty() As OleDbDataReader
'Builds SQL for bind
End Function

....

Function BindOfce() As OleDbDataReader
'Builds SQL for bind based on value of ddlLocCty
End Function

....

Everything works as it should to a degree. The DDL's are only bound
on the initial load of the page. However, when a value is changed in
ddlLocCty, the ddlLocOfce remains unchanged due to the fact that it's
inside the "If Not Page.IsPostBack" block. If I move the bind of the
ddlLocOfce outside of this block, it works as it should. However, I
run into another problem at this point. There are several Validation
Controls on this page, and when the page is posted back by another
method besides the change event on ddlLocCty, the ddlLocOfce is
rebound, causing whatever selection the user made in that to be lost.

What I need to do is move the bind of ddlLocOfce outside of the
post-back check, and determine HOW the page is being posted back. I
need to know that the page is being posted back by virtue of the
autopostback property on ddlLocCty.

Now, I tell you all that (TMI, I know...) to ask this question: Is
there an easy way to tell if the value in ddlLocCty has changed? I
can store the original value in a Viewstate variable and compare it,
but I feel like I'm regressing back to Classic ASP at that point. Is
there a property for a DropDownList that checks to see if it's been
changed? Or is there a better way to go about doing this whole
process?

Any help would be greatly appreciated.

Thanks for your time!
Jul 21 '05 #1
2 3367
Hello Brennon,

The SelectedIndexChanged event of a DropDownList
control will fire whenever the selection is changed. You
can write a handler to respond to a change of the value in
ddlLocCty, and only rebind ddlLocOfce under those
conditions. This should help solve your problem.

Chris
-----Original Message-----
I have a problem that I figured would be relatively common, but havebeen unable to find any information on it as of yet. I have a pagethat contains two DropDownList controls, with the second beingdependent on the value of the first. My DropDownList controldefinitions look like this:

<asp:dropdownlist id="ddlLocCty" runat="server" CssClass="SmlBox"AutoPostback="True" CausesValidation="False"></asp:dropdownlist>
<asp:dropdownlist id="ddlLocOfce" runat="server"
CssClass="SmlBox"></asp:dropdownlist>

When the first list is changed, the second list is rebuilt based onthe selection of the first. My code-behind looks like this:
....
Private Sub Page_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
bind_ddlLocCty()
bind_ddlLocOfce()
bind_ddlReqType()
bind_ddlReqStat()
End If
End Sub

....

Private Sub bind_ddlLocCty()
ddlLocCty.DataSource = BindCty()
ddlLocCty.DataValueField = "cty_cd"
ddlLocCty.DataTextField = "cty_nme_txt"
ddlLocCty.DataBind()
ddlLocCty.Items.Insert(0, New ListItem(" ", ""))
End Sub

Private Sub bind_ddlLocOfce()
ddlLocOfce.DataSource = BindOfce()
ddlLocOfce.DataValueField = "ofce_nbr"
ddlLocOfce.DataTextField = "ofce_txt"
ddlLocOfce.DataBind()
ddlLocOfce.Items.Insert(0, New ListItem(" ", ""))
End Sub

....

Function BindCty() As OleDbDataReader
'Builds SQL for bind
End Function

....

Function BindOfce() As OleDbDataReader
'Builds SQL for bind based on value of ddlLocCty
End Function

....

Everything works as it should to a degree. The DDL's are only boundon the initial load of the page. However, when a value is changed inddlLocCty, the ddlLocOfce remains unchanged due to the fact that it'sinside the "If Not Page.IsPostBack" block. If I move the bind of theddlLocOfce outside of this block, it works as it should. However, Irun into another problem at this point. There are several ValidationControls on this page, and when the page is posted back by anothermethod besides the change event on ddlLocCty, the ddlLocOfce isrebound, causing whatever selection the user made in that to be lost.
What I need to do is move the bind of ddlLocOfce outside of thepost-back check, and determine HOW the page is being posted back. Ineed to know that the page is being posted back by virtue of theautopostback property on ddlLocCty.

Now, I tell you all that (TMI, I know...) to ask this question: Isthere an easy way to tell if the value in ddlLocCty has changed? Ican store the original value in a Viewstate variable and compare it,but I feel like I'm regressing back to Classic ASP at that point. Isthere a property for a DropDownList that checks to see if it's beenchanged? Or is there a better way to go about doing this wholeprocess?

Any help would be greatly appreciated.

Thanks for your time!
.

Jul 21 '05 #2
Chris,

I tried that it worked like a champ...

Thanks so much!

Brennon
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3

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

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
1
by: Donal | last post by:
I have 3 related dropdowns. When the 1st is changed, the 2nd is updated, and when the 2nd is changed, the 3rd is updated. When i change the 1st dropdown (sites), the SelectedIndexChanged fires...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
6
by: Jason | last post by:
I have two drop down lists on my asp.net page, the second of which needs to be filled in based on the selection in the first dropdownlist. The catch however, is that it must occur without a...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
2
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
11
by: harold.gimenez | last post by:
Hi group, I am trying to change the selection of an ASP Dropdownlist just like "Orange" is selected here: http://www.w3schools.com/js/tryit.asp?filename=try_dom_option_selected The...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.