Loop through all text boxes a column in a grid

S

staeri

I have a GridView which dynamically creates text boxes. It could be
between 1 and 100 textboxes depending on how many records there are in
the database.

I need to loop through all the text boxes and to calculate a sum of all
of them which I put into a label in the grid.

I give the text box the name "txtAmount" but the GridView renames each
text box so I never really know the final name.

I'm very grateful for help!

Regards,

Staeri
 
M

mhill37

You don't have to reference the text boxes by name; you could simply
reference them by form element. Every form has an array, which keeps
track of its form elements, and references them starting at 0. For
example, if you have a text box, a radio button, and a pull-down menu,
in that order, you could reference them as formelement[0],
formelement[1], and formelement[2], respectively. Just make sure you
get the references right; if you don't, and you (say) try to parse a
radio button thinking it is a text box, you will get errors.

You would keep track of the size of the array with the length feature.

View the source code on the following page; it shows an example of
referencing the form elements, but the form itself is static (so the
length feature doesn't have to be used):

http://www.akiti.ca/LinLeastSqPoly4.html
 
T

Thomas 'PointedEars' Lahn

You don't have to reference the text boxes by name; you could simply
reference them by form element. Every form has an array, which keeps
track of its form elements, and references them starting at 0.

The `elements' property refers to an HTMLCollection object, not to an
Array object.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top