Adding records to a DropDown control

Discussion in 'ASP .Net' started by David C, Nov 19, 2007.

  1. David C

    David C Guest

    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 C, Nov 19, 2007
    #1
    1. Advertising

  2. David C

    Steph Guest

    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 <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));
    Steph, Nov 27, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vishnu
    Replies:
    1
    Views:
    1,191
    Patrick.O.Ige
    Mar 25, 2006
  2. Mike
    Replies:
    1
    Views:
    796
  3. Luke Airig
    Replies:
    0
    Views:
    776
    Luke Airig
    Dec 31, 2003
  4. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    455
    Ray at
    May 10, 2004
  5. Replies:
    3
    Views:
    645
    Anthony Jones
    Nov 2, 2006
Loading...

Share This Page