473,508 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add list items to dropdownlist in a formview with vb.net

1 New Member
I have a dropdownlist in a formview which looks like this:
Expand|Select|Wrap|Line Numbers
  1. <asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True" 
  2. DataSourceID="SqlDataSource6" DataTextField="StaffName" 
  3. DataValueField="StaffName" SelectedValue='<%# Bind("LetterName") %>'>
  4. <asp:ListItem Value=""> </asp:ListItem>
  5. </asp:DropDownList>
I am trying to add a list item into the dropdownlist to the value of a textbox that is also in the formview, to do this I am using this vb.net code:
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Formview1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.PreRender
  2.  
  3.         Dim dropdown As DropDownList
  4.         Dim listvalue As TextBox
  5.         dropdown = FormView1.FindControl("dropdownlist5")
  6.         listvalue = FormView1.FindControl("textbox1")
  7.  
  8.         dropdown.Items.Add(New ListItem(listvalue.Text, listvalue.Text))
  9.     End Sub
Now, this works to add the textbox value to the dropdownlist if I do not set its selected value property, when I do set the selected value I get "'DropDownList5' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value "

This is the bit I dont understand because the selected value is in the list of items as it is the value I just added in from the textbox, is it checking for the selected value before adding the new list item? If so how do I add the item before the selected value or not set a selected value and have it set selected value in the VB code after adding items to the dropdownlist?
Nov 26 '10 #1
0 1064

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6811
by: Peter Collinson | last post by:
Hi... Is there any way to style a List Item a different color and size than the <LI> in an Ordered List? I'd like a red super-script number and a dark blue text in a page's footnotes. And...
2
3044
by: Unknown User | last post by:
How can I separate list items displayed inline by vertical bars | ? If I use a background image that simulate a vertical bar, and I put this bg image behind each list item, the last list item will...
2
5745
by: deepakp | last post by:
Hi, I'm trying to create a site index page. The page layout will consist of a header, left navigation and content display. The left navigation and content display should look like the image file...
1
3170
by: RSH | last post by:
Hi, I have a situation where I need to add several "Hidden" properties to list items in a dropdownlist. By default the DropDownList item has two properties with regards to the listitems...
0
1681
by: John Dalberg | last post by:
using VS 2005. I have an unordered list with list items which are displayed horizontally. Some of the list items have hyper links and some have checkboxes. The problem is that the...
5
3708
pezholio
by: pezholio | last post by:
Hi, I've got an inline list with a label and checkbox in each list item, each item comes from a MySQL database and, chances are that, in future, the list will become longer. My problem is that...
2
2306
by: Max58kl | last post by:
Hi I am trying to create a bulletted list that has a colored background. The follow css code successfully applies the background color to the list items, but for some reason does not apply the...
4
3021
by: Keith Hughitt | last post by:
For example, If you have a list: <ul> <li>item 1 is short.</li> <li>item 2 is a little bit longer</li> </ul> regardless of the size of the contents of each list item, the element
0
2050
by: c0mrade | last post by:
I have a problem with getting the list items, below is my hibernate code, after that code there is my method ..and below that is my junit test. How can I make sure that query is executing properly,...
16
10601
Frinavale
by: Frinavale | last post by:
What I'd like to do is take a list and display it's items in a circle. For example (the order of the in the circle doesn't matter..except for Item1, it has to be at the top): Item1 ...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.