Adding records to a DropDown control

D

David C

I have a DropDownList control that is bound to a table with an ID and name.
i added a selection option called <new> with 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 = ""
 
S

Steph

David said:
I have a DropDownList control that is bound to a table with an ID and name.
i added a selection option called <new> with 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));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top