GridView loop in js

Discussion in 'ASP .Net' started by DavidC, Feb 25, 2010.

  1. DavidC

    DavidC Guest

    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.
    --
    David
    DavidC, Feb 25, 2010
    #1
    1. Advertising

  2. On Feb 25, 11:53 pm, DavidC <> wrote:
    > 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.
    > --
    > David


    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
    Alexey Smirnov, Feb 26, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Loop the loop...

    =?Utf-8?B?VGltOjouLg==?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,370
    Karl Seguin
    Feb 16, 2005
  2. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,213
    Tim Slattery
    Mar 30, 2005
  3. -
    Replies:
    12
    Views:
    676
    Remon van Vliet
    Jun 15, 2005
  4. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,944
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  5. Isaac Won
    Replies:
    9
    Views:
    350
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page