passing session variable from DDL

K

kai

Hi, All
I put Drop Down List on a ASP.NET form, it contains "CustomerID" from
Northwind Database from SQL Server 2000 "Customers" table. I use
SqlDataAdapter, SqlConnection and DataSet control to connect the
"ddlCustomerID" control. When I select a customerID from the list, let say
"BLONP",
and navigate to next page, it always point to first item on the list
"ALFKI". This is my code on "btnNext_Click" event:

Session("customerID")=ddlCustomerID.SelectedItem.Value
Me.Response.Redirect("next.aspx")

On next.aspx page, I have Session("customerID")="ALFKI" all time. What is my
problem?

Thanks

Kai
 
S

S. Justin Gengo

Kai,

My immediate guess is that you are rebinding the drop down on every post
back.

If this is the case that means that you need to use code like this:

If Not IsPostBack Then
'---Bind your drop down list here
End If

What is happening is that, when the page is loaded, you are rebinding the
drop down. That resets it's selected item to the first item in the list.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top