Changing default selected value in formview dropdownlist

G

Guest

I have a formview with a few dropdownlists (software version, database
version, etc). When a software version is selected, the database version
dropdownlist updates itself accordingly. When in edit mode, everything works
fine - the selected value in each list defaults to the value from the
database record (selectedvalue=bind...).

However, in insert mode (insertitem), it is not working. I pass in a value
on the query string that I would like as the default selected software. The
selected value is set (all debugging shows that it is set) correctly and the
database dropdownlist is populated correctly according to that software, but
the value that is actually displayed in the software dropdown is NOT the
selectedvalue i set - it's the first item in the list - which doesn't match
the correctly populated database dropdown.

I've put a button on the page that sets the selected value to, for example
"3", when clicked. After the page loads I click on the button and it changes
just fine. Also, I've tried changing the code so that whether you are
editing or inserting, the code is always executed the same, but the dropdown
still seems to default to the first item when using the insertitem template.
Is there perhaps something about the insertitemtemplate that, no matter what
you may specify in onLoad, sets all the drop downs to default to the first
item? If that's the case, can I change it? Or am I missing something else?

Any and all help would be greatly appreciated.

Ben
 
E

Elliot Rodriguez

I think this will get you where you need to be.

You can explicitly set that ListItem as Selected. Bear in mind that you may
get an error when you try this first - If you get "A Dropdown cannot have
multiple items selected" you may first have to enumerate through the items
and "unselect" the first one.

for each SoftItem as ListItem in Me.SoftwareDropdown.Items
if SoftItem.Selected then
SoftItem.Selected = false
exit for
end if
next

Me.SoftwareDropdown.Items.FindByValue("3").Selected = true
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top