473,287 Members | 1,399 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,287 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 10366
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.