Click here to Skip to main content
14,638,900 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a text box and a drop down list box. The text box is used to enter new records for the dropdown list box. The dropdown list box is used to select from pre-existing records. What I want to do is to create a new record using the text box but then have the dropdown list box change to the newly created item. I am using the selected value from the drop down listbox in other code and need it to reflect the new record's id when a new record is created.

Any suggestions?
Updated 5-Aug-14 10:45am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can do something like this,
int k = 0;

//inside your Textbox event you prefer
DropDownList1.Items.Add(new ListItem(TextBox1.Text,k.ToString()));
DropDownList1.DataValueField = k.ToString();
int count = DropDownList1.Items.Count;
DropDownList1.SelectedIndex = count - 1;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100