Click here to Skip to main content
15,939,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I want to know how to bind a table from my DB to a TextBox when I select a value from a dropdown list. FYI all my TextBox are created dynamically from another page (let us call it textboxcreate.aspx/.aspx.cs). So I do not create a TextBox from toolbox on this page and give it an asp ID. Rather, the TextBox is already created on another page and I dynamically bind the TextBox to the page we are on now (a separate page, let us call it populatetextbox.aspx/.aspx.cs).

Here is the scenario) There is a dropdown list and a TextBox. There are 3 items in ddl and they are, 0 - Select Below, 1 - Food, 2 - Drinks. When I select "Food" from the dropdown list, the TextBox should populate the word "Chicken" and when I select "Drinks" from the ddl, the TextBox should be populated w/"Drinks".

I believe the solution should be a method that has two parameters, an integer to reference the value selected from the ddl and another int that is the ID of the TextBox that is dynamically binded.

What would possible solutions look like?

What I have tried:

Please help! I have looked at close to 10 sources now on google and all the examples are creating textbox from the toolbox and getting that an asp ID then referencing that. Well yeah thats easy...but thats not the way to do it in my case. Also, many examples I found were an MVC approach, which again is not that way to do it in my case. Just ASP.NET.
Updated 27-May-20 7:56am
[no name] 26-May-20 20:26pm    
You need a "data model"; the one you're implying makes no sense. There is more than just "chicken" when it comes to "food", otherwise, your classification is redundant.
Charrlay 27-May-20 8:22am    
The words have no meaning...simply placeholders if you will.

1 solution

There is an excellent article on CodeProject about data binding:
A Detailed Data Binding Tutorial[^]

Search the article for a TextBox named "txtModel" to see how binding works for a TextBox.

I noticed too late that this was about ASP.NET, the article is about Winforms.
I added the tag ASP.NET to your question.
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