Click here to Skip to main content
15,891,738 members
Please Sign up or sign in to vote.
2.11/5 (9 votes)
See more:
I want to add textual values to a ComboBox in ASP.Net in the code behind.
Does anyone know how I can achieve this?
Posted
Updated 3-Mar-13 21:29pm
v3
Comments
Orcun Iyigun 28-Feb-13 7:35am    
Your question is not clear? Do you want to add your textbox values to your combobox as items?
Prasad_Kulkarni 28-Feb-13 7:38am    
Elaborate some more..
Michael Haephrati 3-Mar-13 13:38pm    
I am going to edit your question's title

You can do it in two ways:
1. Either you can alter your datasource and rebind the DropDownList.
2. Insert the items in DropDownList in TerxtChanged event of your TextBox(AutoPostBack property should be true for textbox to fire server side event). Try this:
C#
drpList.Items.Insert(0, new ListItem(TextBox1.Text.Trim(), TextBox1.Text.Trim()));



--Amit
 
Share this answer
 
Use
C#
//Code here to populate DropDownList
DropDownListID.Items.Insert(0, new ListItem("text", "value")
///
///  0 is the index at which you want to insert the text. Text means the text
///  which is shown to the user and value is a unique value (enum or a number) 
///  which can be used in the code-behind to uniquely identify a dropdown item.



I hope this helped you,
use the "Have a question or a comment?" button below to ask for further clarification.

cheers,
Marco Bertschi
 
Share this answer
 
v6

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