insert data from 10 textboxes
-
I have a simple question wich probably can be easily answered but I'm clueless. On a webform people can invite friends (lets say 10). So I have 10 times dropdown: Mr. / Mrs., 10 times: Tetxtbox; firstname and 10 times: Textbox emailadres. I want to insert these in tabel tblfriends. Before I insert I would like to do some validation to see if the friend allready exists in the database, sent an email to the person etc. But that is not the point really. Would I end up writing ten insert queries with lstmrmrs1, txtfirstname1, txtemal1 then lstmrmrs2, txtfirstname2, txtemal2, etc. up to 10 ? I have googled quite a bit but can't find a hint.
-
I have a simple question wich probably can be easily answered but I'm clueless. On a webform people can invite friends (lets say 10). So I have 10 times dropdown: Mr. / Mrs., 10 times: Tetxtbox; firstname and 10 times: Textbox emailadres. I want to insert these in tabel tblfriends. Before I insert I would like to do some validation to see if the friend allready exists in the database, sent an email to the person etc. But that is not the point really. Would I end up writing ten insert queries with lstmrmrs1, txtfirstname1, txtemal1 then lstmrmrs2, txtfirstname2, txtemal2, etc. up to 10 ? I have googled quite a bit but can't find a hint.
-
You should look into the concept of looping. A loop will enable you to repeatedly execute some of your code, so that you don't have to write the same code over and over again. --- b { font-weight: normal; }
-
That is a little bit too vague... I think it should be solved with the creation of a datatable somehow but dunno more than that. With only a loop I still have the problem that the textboxes have a name: textbox1, textbox2, etc.
Yes, I was a bit vague, but your question was quite vauge. You don't need a datetable to update several records, but you can use that if you want. I would just do the updates one by one. That's the way the datatable does them in the end anyway. The textbox names is not a problem. You can get the textboxes by name: Page.FindControl("textbox" + i) Or you can put references in an array: TextBox[] boxes = new TextBox[] { textbox1, textbox2 ... }; --- b { font-weight: normal; } -- modified at 15:56 Sunday 8th January, 2006