GridView loop in js

  • Thread starter Thread starter DavidC
  • Start date Start date
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.
 
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
 
Back
Top