Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
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?
Posted
Updated 5-Aug-14 10:45am
v2

1 solution

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

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900