title: How to Read Value From ASP.net TextBox Template Column in JavaScript
body: <p>I am trying to read cells value from asp.net GridView control in Client Site JavaScript.
  Below is my GridView HTML View.</p>
  
  <pre><code>&lt;asp:GridView 
  ID="GridView1" 
  runat="server" 
  AutoGenerateColumns="False" 
  Width="596px" 
  DataKeyNames="Key" &gt;
  
  &lt;Columns&gt;
      &lt;asp:BoundField DataField="Key" HeaderText="Key" SortExpression="key" Visible="False" /&gt;
      &lt;asp:BoundField DataField="StockId" HeaderText="StockId" Visible="False" /&gt;
      &lt;asp:BoundField DataField="Freq1" HeaderText="Freq1" Visible="False" /&gt;
      &lt;asp:BoundField DataField="Freq2" HeaderText="Freq2" Visible="False" /&gt;     
  
      &lt;asp:BoundField DataField="MedicineName" HeaderText="MedicineName" ReadOnly="true" /&gt;
  
      &lt;asp:TemplateField HeaderText="DoseQty" &gt;                                                        
          &lt;ItemTemplate&gt;
              &lt;asp:TextBox ID="txtDoseQty" Text='&lt;%# Bind("DoseQty") %&gt;' runat="server"
              Height="23px" Width="38px" onchange="javascript:dataChange(event);" &gt;&lt;/asp:TextBox&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
  
      &lt;asp:BoundField DataField="DoseUOM" HeaderText="DoseUOM" ReadOnly="true" /&gt;
  
      &lt;asp:TemplateField HeaderText="Duration"&gt;
          &lt;EditItemTemplate&gt;
              &lt;asp:TextBox ID="Duration" runat="server" Height="16px" 
                  Text='&lt;%# Bind("Duration") %&gt;' Width="45px" onkeypress="return isNumberKey(event);"&gt;&lt;/asp:TextBox&gt;
          &lt;/EditItemTemplate&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="lblDuration" Text='&lt;%# Bind("Duration") %&gt;'  runat="server"&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
  
      &lt;asp:TemplateField HeaderText="Delete All"&gt;
          &lt;HeaderTemplate&gt;
              &lt;asp:CheckBox ID="chkHeaderDelete" runat="server" Text="Delete All" 
                  onclick="javascript:SelectheaderCheckboxes(this)" /&gt;                                                            
          &lt;/HeaderTemplate&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:CheckBox ID="chkItemDelete" runat="server" AutoPostBack="true"
                  Text="Delete" onclick="javascript:SelectitemCheckboxes(this)"  /&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
  
      &lt;asp:CommandField HeaderText="Update" 
          ShowEditButton="True"                                                         
          CausesValidation="false"  /&gt;
  
  &lt;/Columns&gt;
  </code></pre>
  
  <p></p>
  
  <p>I am using javascript function to read this grid view.</p>
  
  <pre><code>var grid = document.getElementById("&lt;%= GridView1.ClientID %&gt;");
  var OutputString = "";
  if (grid.rows.length &gt; 0) {
  for (i = 1; i &lt; grid.rows.length - 1; i++) {
      for (j = 0; j &lt; grid.rows[i].cells.length; j++) {
          OutputString += "grid.rows[i].cells[" + j + "]  :" + grid.rows[i].cells[j] +
              "\ngrid.rows[i].cells[" + j + "].innerText :" + grid.rows[i].cells[j].innerText;
          OutputString += "\n\n";             
      }
  }
  }
  </code></pre>
  
  <p>Here is my output.</p>
  
  <pre><code>---------------------------
  Message from webpage
  ---------------------------
  grid.rows[i].cells[0]  :[object]
  grid.rows[i].cells[0].innerText :Abd pant XXXL
  
  grid.rows[i].cells[1]  :[object]
  grid.rows[i].cells[1].innerText : 
  
  grid.rows[i].cells[2]  :[object]
  grid.rows[i].cells[2].innerText :Pieces
  
  grid.rows[i].cells[3]  :[object]
  grid.rows[i].cells[3].innerText :1 
  
  grid.rows[i].cells[4]  :[object]
  grid.rows[i].cells[4].innerText :Delete 
  
  grid.rows[i].cells[5]  :[object]
  grid.rows[i].cells[5].innerText :Edit
  
  ---------------------------
  OK   
  ---------------------------
  </code></pre>
  
  <p>My problem is I don't know how to get the value from grid.rows[i].cells[1] which is included ASP.net TextBox Control as TemplateColumn.</p>
  
  <p>Every suggestion will be really appreciated.</p>