GridView loop in js

D

DavidC

I would like to loop through all of the controls in a GridView inside form1
and grab the values (innerHTML) of TextBox controls that contain "txtWeek" as
part of the ID name. I need to do it at the client so I was thinking of
Javascript using getElementById but that requires an exact name. Can anyone
help on how to do this and a short example? Thanks.
 
A

Alexey Smirnov

I would like to loop through all of the controls in a GridView inside form1
and grab the values (innerHTML) of TextBox controls that contain "txtWeek" as
part of the ID name.  I need to do it at the client so I was thinking of
Javascript using getElementById but that requires an exact name.  Can anyone
help on how to do this and a short example?  Thanks.

Hi David,

You can use DOM and get all controls e.g. with tag <div>

var lists = document.getElementsByTagName("div");
for (var i = 0; i < lists.length; i++)
{
if (lists.id.indexOf('txtWeek) !== -1) {
....
}
}

to get controls inside the grid you can use

document.getElementById('gridID').getElementsByTagName...

Hope this helps
 

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

Top