Populate ASP.NET textbox from combobox selected index change

I am very new to ASP.NET.I have a an ASP.NET page with an AJAX Combobox and a TextBox. The combobox populates from a database and has value of ID and displays Name. The textbox should display Address. All i want to do is change the value in the Address textbox when the index on the Name combo …

via Asp.Net Developed Tutorials » Search Results » ajax:

Populate ASP.NET textbox from combobox selected index change

I am very new to ASP.NET.
I have a an ASP.NET page with an AJAX Combobox and a TextBox. The combobox populates from a database and has value of ID and displays Name. The textbox should display Address. All i want to do is change the value in the Address textbox when the index on the Name combo box changes. And then be able to change the address and save it back to the database. How do I do this (simple?) task?
Code so far…

DataValueField=”Id” MaxLength=”0″ Style=”display: inline;”
AutoCompleteMode=”SuggestAppend”
onselectedindexchanged=”ComboBox1_SelectedIndexChanged”>

SelectCommand=”SELECT [Id], [Name], [Address] FROM [tblStudents]“>


………………………………………

Try with the below markup. I’ve used DropDownList, it could be replaced with AJAX ComboBox. The DetailsView could be further enhanced with CSS and ItemTemplate. You could put more fields into the ItemTemplate like City, Country and so on.
DataSourceMode=’DataSet’ SelectCommand=’Select ID, [First Name], [Last Name] from Students’
runat=’server’ >

SelectCommandType=”Text” SelectCommand=’Select [ID], [Address] from [Students] where ID=@id’
runat=’server’>



DataTextField=”First Name” DataValueField=’ID’>








………………………………………

In your ComboBox1_SelectedIndexChanged event. Set TextBox1.Text = CurrentAddress variable. In reality, I am not a big fan of bindings commands directly in the asp.
I would create a Sub that is called LoadMyComboBox() which would fire in the Page_Load() event.
I would assume your going to have a button or some type of event that would be fired to perform your update? TextChanged would be overkill here. Adding an update button and then building your update command in the code behind would handle your update. Once that update is complete you can simply call LoadMyComboBox() again to refresh your combobox to refresh any necessary changes and do whatever you want with your textbox at this time as well.
………………………………………

u can do this by using a dropdownlist itself. In the DropDownList’s SelectedIndexChanged event, bind the address to the TextBox control according the dropdownlist selection and pass this as a parameter and save it in database.

For more info: Populate ASP.NET textbox from combobox selected index change

Asp.Net Developed Tutorials » Search Results » ajax

Populate ASP.NET textbox from combobox selected index change

Share this post:

Related Posts

Leave a Comment