Adding records to a DropDown control

  • Thread starter Thread starter David C
  • Start date Start date
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 = ""
 
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));
 
Back
Top