pmlevere
pmlevere

Reputation: 77

VB Load stored session variable into an asp dropdown list

I have a VB web app where I am allowing the user to enter data into textboxes and allowing the user to select several dropdown values from a sql data table. I'm trying to save the data into session variables and load the data on a later page.

I've figured out how to save and load the data in the textboxes but am having issues with the dropdown lists.

To set the session variables to the user entered textbox values:

Session("CompanyName") = txtCompanyName.Text
Session("AnnualRevenue") = txtAnnualRevenue.Text

And I load similarly:

txtCompanyName.Text = Session("CompanyName")
txtAnnualRevenue.Text = Session("AnnualRevenue")

That all works properly, but i'm not sure how do user dropdowns in the same way.

Here is my code to set the session variable to the user selected value:

Session("DDLHQ") = DropDownListHQ.SelectedValue

This sets the session variable to the string of the selected value.

How do I load the saved session variable from the previous selection of the dropdown list into a dropdown list on another page?

I'm completely lost on this right now.

Upvotes: 1

Views: 1260

Answers (1)

Bill Hall
Bill Hall

Reputation: 586

You should make sure your DropDownList is populated with items first, and you should check to see if the item you are attempting to assign as the SelectedValue actually exists.

If Not (DropDownListHQPage2.Items.FindByValue(Session("DDLHQ")) Is Nothing) Then DropDownListHQPage2.SelectedValue = Session("DDLHQ")

Upvotes: 2

Related Questions