Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox selectedvalue is nothing 1

Status
Not open for further replies.

xenology

Programmer
May 22, 2002
51
US
I have four listbox controls on my page. Each is bound to a dataset (listbox.datasource to the dataset, listbox.datatextfield to dataset.column, listbox.datavaluefield to dataset.keycolumn). In form load I set the parameter to the data adapter, fill the dataset, and listbox.databind. When running the page shows and the listboxes display their data. When you click on a row in the listbox and click the 'Add' button, I am trying to get the one they selected and insert that info into the table. However, listbox.selectedvalue = "" and listbox.selecteditem = Nothing even though it is showing as highlighted on the page.
Any Ideas?
 
Try
Code:
ListBox1.SelectedItem.Value


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
enabledviewstate = true must be on for the page if you're getting the value on a button click or some other form of postback.
 
checkai,

I disagree actually! Using ListBox1.SelectedItem.Value will still return the selected value if the enabledviewstate is set to False.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
It was actually still the code of listbox.selectedvalue.

my problem was in Form Load. It seems the page was refreshing before the click event of the button. To correct the problem, I encased the data adapter / dataset / listbox binding with an IF NOT thisPage.PostBack THEN statement. At that point, selected value started returning the info.

thanks for the thoughts though!~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top