title: Get gridview row values when checkbox checked
body: <p>I have a gridview with checkboxes to select the row. On checking the checkbox I need to get the row values into a string/session. Below is the code</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"                 
      OnRowCancelingEdit="GridView1_RowCancelingEdit"    
      OnRowEditing="GridView1_RowEditing"  OnRowUpdating="GridView1_RowUpdating"  OnRowDeleting="GridView1_OnRowDeleting"  OnPageIndexChanging="GridView1_PageIndexChanging" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"  Width ="1000px" class="grid" AllowPaging="True" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last" PageButtonCount="2" PagerSettings-Mode="NumericFirstLast" PageSize="5"&gt;
      &lt;PagerSettings Mode="NumericFirstLast" PageButtonCount="2"  FirstPageText="First" LastPageText="Last"/&gt; 
      &lt;Columns&gt;   
         &lt;asp:TemplateField HeaderText="Id"&gt;   
              &lt;ItemTemplate&gt;   
                 &lt;asp:CheckBox ID="CheckBox3" runat="server" /&gt;
              &lt;/ItemTemplate&gt;   
          &lt;/asp:TemplateField&gt;   
          &lt;asp:TemplateField HeaderText="Connection"&gt;   
              &lt;ItemTemplate&gt;   
                  &lt;asp:Label ID="lbl_conn" runat="server" Text='&lt;%#Eval("Connection") %&gt;'&gt;&lt;/asp:Label&gt;   
              &lt;/ItemTemplate&gt;   
          &lt;/asp:TemplateField&gt;   
  
                          &lt;asp:TemplateField HeaderText="UserID"&gt;   
              &lt;ItemTemplate&gt;   
                  &lt;asp:Label ID="lbl_Usrid" runat="server" Text='&lt;%#Eval("UserID") %&gt;'&gt;&lt;/asp:Label&gt;   
              &lt;/ItemTemplate&gt;   
              &lt;EditItemTemplate&gt;   
                  &lt;asp:TextBox ID="txt_Usrid" runat="server" Text='&lt;%#Eval("UserID") %&gt;'&gt;&lt;/asp:TextBox&gt;   
              &lt;/EditItemTemplate&gt;   
          &lt;/asp:TemplateField&gt; 
          &lt;asp:TemplateField HeaderText="Password"&gt;   
              &lt;ItemTemplate&gt;   
                  &lt;asp:Label ID="lbl_pwd" runat="server" Text='&lt;%#Eval("Password") %&gt;'&gt;&lt;/asp:Label&gt;   
              &lt;/ItemTemplate&gt;   
              &lt;EditItemTemplate&gt;   
                  &lt;asp:TextBox ID="txt_pwd" runat="server" Text='&lt;%#Eval("Password") %&gt;'&gt;&lt;/asp:TextBox&gt;   
              &lt;/EditItemTemplate&gt;   
          &lt;/asp:TemplateField&gt; 
          &lt;asp:TemplateField HeaderText="Connection Name"&gt;   
              &lt;ItemTemplate&gt;   
                  &lt;asp:Label ID="lbl_conName" runat="server" Text='&lt;%#Eval("Connection_Name") %&gt;'&gt;&lt;/asp:Label&gt;   
              &lt;/ItemTemplate&gt;   
              &lt;EditItemTemplate&gt;   
                  &lt;asp:TextBox ID="txt_conName" runat="server" Text='&lt;%#Eval("Connection_Name") %&gt;'&gt;&lt;/asp:TextBox&gt;   
              &lt;/EditItemTemplate&gt;   
          &lt;/asp:TemplateField&gt;   
  
  
             &lt;asp:TemplateField HeaderText="Edit"&gt;   
              &lt;ItemTemplate&gt;   
                  &lt;asp:Button ID="btn_Edit" runat="server"  Text=" Edit" class=" btnEdit"  CommandName="Edit" /&gt;   
              &lt;/ItemTemplate&gt;   
              &lt;EditItemTemplate&gt;   
                  &lt;asp:Button ID="btn_Update" runat="server" class=" btnEdit" Text="Update" CommandName="Update"/&gt;   
                  &lt;asp:Button ID="btn_Cancel" runat="server" class=" btnEdit" Text="Cancel" CommandName="Cancel"/&gt;   
              &lt;/EditItemTemplate&gt;   
          &lt;/asp:TemplateField&gt;  
         &lt;asp:TemplateField HeaderText="Delete"&gt;   
              &lt;ItemTemplate&gt;   
                  &lt;asp:Button ID="btn_Delete" runat="server" class=" btnDelete" Text="Delete" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this event?')" /&gt;   
              &lt;/ItemTemplate&gt;   
  
          &lt;/asp:TemplateField&gt; 
      &lt;/Columns&gt;   
  &lt;/asp:GridView&gt;   
  </code></pre>
  
  <p>There is a button below the grid. on click of the button I need to get the values.</p>
  
  <pre><code>protected void LinkButton1_Click(object sender, EventArgs e)
  {
      foreach (GridViewRow item in GdvTestData.Rows)
      {
          CheckBox chk = (item.FindControl("CheckBox3") as CheckBox);
          if (chk.Checked)
          {
              string conn = item.Cells[1].Text;
          }
      }
  }
  </code></pre>
  
  <p>But am getting null value for <code>string conn = item.Cells[1].Text;</code>
  where am I going wrong</p>