简体   繁体   中英

How I can use the value of a textbox which is in a gridView in the code behind without using the FindControl() method

How can do I that? Does anyone have a solution. It is also looking tricky but I don't have an answer.

Did you try something like this?

((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0])

 <script type="text/javascript">
  function SelectAll(id)
  {
    //get reference of GridView control
    var grid = document.getElementById("<%= GridView1.ClientID %>");
    //variable to contain the cell of the grid
    var cell;

    if (grid.rows.length > 0)
    {
      //loop starts from 1. rows[0] points to the header.
      for (i=1; i<grid.rows.length; i++)
      {
        //get the reference of first column
        cell = grid.rows[i].cells[0];

        //loop according to the number of childNodes in the cell
        for (j=0; j<cell.childNodes.length; j++)
        {       
          //if childNode type is textbox or label or...         
          if (cell.childNodes[j].type =="TextBox")
          {
          //perform ur task here
        }
        }
      }
    }
  }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM