I have Web Form (.aspx file) with a fair number of textboxes (<asp:textbox
.... />) that I need to fill from a database and then save back to the
database when I'm done. This presumably must be a fairly common problem.
If I use brute force, I finish up with a lot of assignments in the
Page_Load(...) routine and the same number backwards in the OnClick handler
for the submit.
In C++ I would create an single array of pointers to the text box objects
and then have two loops using the textbox name to transfer the column info
into or out of the database.
Is there a clever way in C# to do the equivalent?
If I could get hold of all the controls in the page, it seems like I could
do something like:
String[] textBoxNames = { "T1", "T2", "T3" ...};
DataRow dataRow = dataSet.Tables["MyTable"].Rows[iSelectedRow];
....
foreach(String textBoxID in textBoxNames) {
TextBox tb = SomeSortofCollection.FindControl(textBoxID);
// when we fill the text box from the data store
tb.Text = dataRow[textBoxID];
}
and when the data is to be stored away, a similar loop, but with the last
line changed.
dataRow[textBoxID] = tb.Text;
I don't know what to put in for the collection in which I should be looking
to find the control!
Can anyone suggest an example that shows how to do this sort of thing.
Ed
--
Edward E.L. Mitchell
6707 Daniel Court
Fort Myers, FL 33908