I have 2 lists of strings and I’d like to dynamically create a grid of textboxes:
List<string> X = {"A", "B", "C"};
List<string> Y = {"1", "2", "3", "4"};
A B C
1 TBX TBX TBX
2 TBX TBX TBX
3 TBX TBX TBX
4 TBX TBX TBX
[Button]
When I enter data into the textboxes and click the button, I’d like to be able to iterate over these textboxes and determine the “X” and “Y” coordinates associated with each textbox.
I can probably figure out how to dynamically create this grid of textboxes, but I think I’ll run into issues when I post the data. How do I get the values from the dynamically created textboxes after a postback?
I’ll have no issue doing the iteration and actual logic but I can’t figure out how to get the data into a container so that it can be iterated. Will I have to dynamically create the textboxes again while reading the posted data? What does that look like?
Here is another approach. You can have a place holder in the asp.net page. In code behind dynamically create a table with dynamic text boxes and insert it inside place holder. In this instance you have control over the ID of each textbox. On post back values entered into the text boxes will be retained (since IDs are definite you can do javascript manipulation as well)
Here is the aspx
Code behind
Few screen shots
input screen with data
on postback (submit)
after submit