473,545 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page Post Back -- how to retain selecteditem.va lue of TWO dropdowns???

Hi,

On Page Load (if not postback), the user selects a choice from
dropdownlist1.

On SelectedItemCha nged for dropdownlist1, dropdownlist2 is populated
and the user selects an item.

I cannot find a combination where I can RETAIN both values during
postback...if I put if not posback on the change event of
dropdownlist1, it doesn't populate #2...

Any help appreciated!

Kathy
Nov 17 '05 #1
6 5652
What does your event handler for SelectedItemCha nged for dropdownlist1 look
like?

Todd Thompson
Nov 17 '05 #2
Here are both pageload and selecteditemcha nged...when I load the page,
it let's me select the Customer (control 1), and DOES filter the second
control, but at the same time, resets control 1 to "Select
Customer"...ugh .

Both controls set to autopostback and enable viewstate.

Any ideas?

Thanks.
KathyBurke

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack Then
Dim Conn1 As OleDbConnection
Dim Rdr1 As OleDbDataReader
Dim Cmd1 As OleDbCommand
Dim strSQL As String
Conn1 = New OleDbConnection (strConn)
strSQL = "SELECT DISTINCT Customer FROM tblCustomers ORDER
BY Customer"
Cmd1 = New OleDbCommand(st rSQL, Conn1)
Conn1.Open()
Rdr1 = Cmd1.ExecuteRea der()
cboCust.DataSou rce = Rdr1
cboCust.DataBin d()
cboCust.Items.I nsert(0, "Select Customer")
cboCust.Selecte dIndex = 0
Rdr1.Close()
Conn1.Close()
End If

End Sub

Private Sub cboCust_Selecte dIndexChanged(B yVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cboCust.Selecte dIndexChanged

Dim Conn2 As New OleDbConnection ()
Dim Rdr2 As OleDbDataReader
Dim strSQL2 As String = "SELECT Assy FROM tblAssy WHERE
([Customer] = @customer) ORDER BY Assy"
Dim Cmd2 As New OleDbCommand(st rSQL2, Conn2)
Conn2 = New OleDbConnection (strConn)
Dim prmCustomer As OleDbParameter = New
OleDbParameter( "@customer" , OleDbType.VarCh ar, 50)
prmCustomer.Val ue = cboCust.Selecte dItem.Value
Cmd2.Parameters .Add(prmCustome r)
Cmd2.Connection = Conn2
Conn2.Open()
Rdr2 = Cmd2.ExecuteRea der()
cboAssy.DataSou rce = Rdr2
cboAssy.DataBin d()
cboAssy.Items.I nsert(0, "Select Assembly")
cboCust.Selecte dIndex = 0
Rdr2.Close()
Conn2.Close()
End Sub
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3
In your handler you have the following line:
On 27-Jun-2003, Kathy Burke <an*******@devd ex.com> wrote:
cboCust.Selecte dIndex = 0

If I'm understanding your code and problem correctly, you are setting the
index of the drop down to the first item instead of leaving it set to its
previous value.
Todd Thompson
Nov 17 '05 #4
You are correct in that the code contained within the Page_Load function and
in the IF NOT POSTBACK conditional won't be run.

But in your event handler cboCust_Selecte dIndexChanged, you are setting the
cboCust.Selecte dIndex=0 which will affect that drop down on the current
page.

Todd Thompson
Nov 17 '05 #5
Todd,

I'm an idiot...I copied the code for cboAssy but forgot to change that
control ref...THANK YOU...

KathyBurke

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #6
Kathy,

No problem, I've done the same thing myself.

Glad to be of help.

Todd
Nov 17 '05 #7

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

Similar topics

0
1970
by: Pat Patterson | last post by:
I'm having serious issues with a page I'm developing. I just need some simple help, and was hoping someone might be able to help me out in here. I have a form, that consists of 3 pages of fields. I'd like to create a page in which all of this is stored as you move along as hidden variables, until the end, when the user submits. I can't...
4
3935
by: Justin Bartels | last post by:
Hi, I have been struggling with an unusual problem with a dropdownlist web control for quite some time now. Cutting straight to the problem, I am setting the selected item in the dropdownlist using the IndexOf method of the list's items collection (in my debugging case this successfully sets the selectedindex to 15). After postback, the...
0
1236
by: Goober at christianDOTnet | last post by:
I'm wanting to fix the following on a web page without really re-inventing anything. What I have is a vb web page with a radiobuttonlist where I can pick Current or History year. Underneath that is a listbox that has a set of reports in it, some for current year, some for history year. If Current year is chosen, 6 reports (depending on...
2
12347
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the users need not enter values in all the controls. they can leave the textbox blank, and select values from one drop down, or any other combinations....
1
3737
by: Stimp | last post by:
I have 2 dropdowns, county and district. When the county changes, I want the district dropdown to automatically update with a list of districts in that county, but I don't want the page to have to reload when county changes. I remember doing this before in classic ASP with javascript, can I do this with a dropdownlist in ASP.NET or should...
6
4849
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still...
7
1333
by: surikumarvinod | last post by:
hello, I have a page in wich i have 3 dropdowns and a grid view. when i click on the edit button in grid view to update a record it takes me to edit page. what i want is when i come back from the edit page back to the page with grid view and the dropdowns. The selected index of the dropdowns should be the same as when i clicked the edit...
5
5013
by: Hans Kesting | last post by:
Hi, Is there good information about the asp.net page lifecycle in combination with dynamically loaded controls? Or on "how to build dynamic controls"? I keep hitting problems where values are not available at the moment I need them. Current problem: In a dynamically loaded ascx there is a dropdown. Based on the selected value (reloading...
2
12220
by: qwedster | last post by:
Folks! The following is a "Hello World" kind of code for ViewState. I just want to know how to retain the ViewState 1) while Page Refresh when using UpdatePanel and also 2) While I reverting back to the page after round trip when using UpdatePanel? In the following code snippet the ViewState is killed when I click page refresh or when I go...
0
7478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7923
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.