473,379 Members | 1,379 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.

Adding records to a DropDown control

I have a DropDownList control that is bound to a table with an ID and name.
i added a selection option called <newwith a value = -1.
When I choose this -1 value record I use OnSelectedIndexChange event to add
the new country to the table and that is working fine. next I want to
refresh the dropdownlist to show the new country added and have that as
selected value on the current record. Below is my code and is erroring on
the varControl.SelectedValue = lngNewID line with error "Databinding methods
such as Eval(), XPath(), and Bind() can only be used in the context of a
databound control". Thanks.

David

Below is code and above this code is where I add the new record to the
lookup table (and that works).

Dim row As FormViewRow = fvPatents.Row

Dim varControl

SqltlkpCountries.DataBind()

varControl = row.FindControl("ddlCountryID")

varControl.SelectedValue = lngNewID

txtNewText.Text = ""
Nov 19 '07 #1
1 1046
David C wrote:
I have a DropDownList control that is bound to a table with an ID and name.
i added a selection option called <newwith a value = -1.
When I choose this -1 value record I use OnSelectedIndexChange event to add
the new country to the table and that is working fine. next I want to
refresh the dropdownlist to show the new country added and have that as
selected value on the current record. Below is my code and is erroring on
the varControl.SelectedValue = lngNewID line with error "Databinding methods
such as Eval(), XPath(), and Bind() can only be used in the context of a
databound control". Thanks.

David

Below is code and above this code is where I add the new record to the
lookup table (and that works).

Dim row As FormViewRow = fvPatents.Row

Dim varControl

SqltlkpCountries.DataBind()

varControl = row.FindControl("ddlCountryID")

varControl.SelectedValue = lngNewID

txtNewText.Text = ""

you must use :
varControl.SelectedIndex = varControl.Items.IndexOf(
varControl.Items.FindByValue(lngNewId));

Nov 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: k | last post by:
Hi all I split a database in a table-part and a all-the-rest-part and linked the tables, but my code adding records to a table crashes on Set rs = db.OpenRecordset("tblDeltakelse",...
5
by: Tim | last post by:
I have block of code adding values to dropdown list under if (!Page.IsPostBack) { adding items } else { refreshing data }
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: C Downey | last post by:
I have a registration form that should load different web user controls based on the selection of a dropdown list. Basically, the user follows the following steps: 1. user comes to very basic...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
1
by: JohnR | last post by:
I'm using oledb to an Access datatable. I load the table into a dataset. I create databindings to link the fields on my form to the corresponding fields in the datatable. The tables...
5
by: axsprog | last post by:
I am quite skilled with Access, VBQ, ADo, etc. but to I can no longer ignore the demands from clients to provide WEB enabled forms for their data - so hence I have begun to develop DAP's for some....
1
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a...
9
by: Kadett | last post by:
Hi all, I have following problem: I'm creating a ListView (Details) control at run-time and filling it with some records (let's say 10 000). This operation seems to be quite fast, but when I call...
11
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.