Access CheckBox in GridView by row index with javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vladzeem
    New Member
    • Dec 2007
    • 6

    Access CheckBox in GridView by row index with javascript

    Hi there,
    I have a problem to access a checkbox inside GridView using
    row index using javascript.
    Here is the code:
    [CODE=javascript]var c;
    var cellValue;
    var rCount = 0;
    var cellControl;

    gridViewCtl = document.getEle mentById("ctl00 _ContentPlaceHo lder1_gvQueue_Q ueue");
    rCount = gridViewCtl.row s.length;
    for(c=2; c<=rCount; c++)
    {
    var row = gridViewCtl.row s[c];
    cellValue = getCellValue(c, 10); // Gets value in the 10 cell - OK
    cellControl = getCellControl( c,1); // Trying to get check box in 1 cell
    // alert(cellContr ol);
    if( cellValue == "Test" )
    {
    // set CheckBox status depends on cellValue on current row
    }
    }

    function getCellControl( rowIdx, colIdx)
    {
    var gridCell = getGridColumn(r owIdx, colIdx);

    if (null != gridCell)
    {
    // here is the isseu:
    if(gridCell.typ e =="checkbox")
    {alert("!");}
    else{alert("-" + gridCell.type); }
    return gridCell.contro ls;
    }
    return null;
    }
    [/CODE]
    Thanks for your help

    Vladzeem
    Last edited by acoder; Dec 6 '07, 03:57 PM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Show the HTML code for the table/grid.

    Please use code tags when posting code. Thanks!

    Comment

    • Vladzeem
      New Member
      • Dec 2007
      • 6

      #3
      OK, I have found solution - used innerHTML to get id, name, type of control:

      [code=javascript] function getCellControl( rowIdx, colIdx)
      {
      var gridCell = getGridColumn(r owIdx, colIdx);
      var type = null;
      var typePos;
      var ctrId;
      var idPos;
      var delPos;
      var inHTML;
      var buf;
      var chkStatus;
      var statPos;

      if (null != gridCell)
      {
      inHTML = gridCell.innerH TML;
      typePos = inHTML.indexOf( "type")

      if(typePos > 0)
      {
      typePos = typePos + 5;
      buf = inHTML.substrin g( typePos );
      delPos = buf.indexOf(" ");

      if(delPos > 0)
      {
      /* Get Control type */
      type = inHTML.substrin g( typePos, (typePos + delPos));

      if(type == "checkbox")
      {
      idPos = inHTML.indexOf( "id")

      /* Get CheckBox Id */
      if(idPos > -1)
      {
      idPos = idPos + 3;
      ctrId = inHTML.substrin g(idPos, (typePos - 5))
      }

      /* Get CheckBox status */
      statPos = buf.indexOf(" ");
      if(statPos > -1)
      {
      buf = buf.substring(s tatPos + 1);
      delPos = buf.indexOf(" ");
      chkStatus = buf.substring(0 , delPos);
      }
      }
      }
      }
      }
      return ctrId;
      }[/code]
      Last edited by acoder; Dec 6 '07, 06:46 PM. Reason: Added code tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You didn't need to use innerHTML for that. You could've got the input object and checked its type for "checkbox", and got the id, etc.

        Please remember to use code tags when posting code.

        Comment

        • Vladzeem
          New Member
          • Dec 2007
          • 6

          #5
          Originally posted by acoder
          You didn't need to use innerHTML for that. You could've got the input object and checked its type for "checkbox", and got the id, etc.

          Please remember to use code tags when posting code.
          How to use input object ?

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            gridCell.getEle mentsByTagName( "input") would give you an array of input elements.

            Comment

            • Vladzeem
              New Member
              • Dec 2007
              • 6

              #7
              Originally posted by acoder
              gridCell.getEle mentsByTagName( "input") would give you an array of input elements.
              Thanks a lot for your help

              Vladzeem

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                You're welcome.

                Comment

                Working...