By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

Changing default selected value in formview dropdownlist

P: n/a
Ben
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
May 19 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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").Selecte d = true

"Ben" <Be*@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
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

May 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.