473,379 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Changing default selected value in formview dropdownlist

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
1 10372
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
2
by: huzz | last post by:
How do i make a dropdownlist selected value based on the value i retrive from the database. Basically i have an edit page and like to display the default value in a dropdown list from the...
11
by: Michael Groeger | last post by:
Hi, is it possible to leave a DropDownList's selection empty? Our application requires for some ddl's that they are kept blank w/o an initial value so that we can add a RequiredFieldValidator to...
1
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. ...
0
by: Jon Paal | last post by:
--dropdownlist value isn't being saved to database from FORMVIEW --field PriorityID is datatype "number" (integer) what's missing ???? '=========code============= <asp:Content ID="Content1"...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
1
by: seanwalsh | last post by:
Hi I have a DDLB in a gridview that allows record entry. The default is set by the QueryString. Here is the code: <FooterTemplate> <asp:DropDownList...
5
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.