title: How to get cell value in a GridView on LinkButton Click Event? Or RowCommand?
body: <p>I Have a GridView which conntains multiple records and couple of Link Buttons Named Edit and Detail. Now i want to Get the Name of the User (NOT Index), when a user click on Detail Link Button. Like "Name", "FatherName" etc
  Here is the .aspx code</p>
  
  <pre><code>&lt;asp:GridView ID="dgvEmployeesInformation" runat="server" CssClass=" table table-bordered table-hover table-responsive" DataKeyNames="Id" AutoGenerateColumns="False" OnRowCommand="dgvEmployeesInformation_RowCommand" OnRowDataBound="dgvEmployeesInformation_RowDataBound" AllowPaging="True" AllowSorting="True" OnPageIndexChanging="dgvEmployeesInformation_PageIndexChanging"&gt;
      &lt;%--1st Column--%&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField HeaderText="ID" DataField="Id" ControlStyle-BackColor="#0066ff" Visible="False"&gt;
              &lt;ControlStyle BackColor="#0066FF"&gt;&lt;/ControlStyle&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField HeaderText="Name" DataField="Name" /&gt;
          &lt;asp:BoundField HeaderText="Employee No" DataField="EmployeeNo" /&gt;
          &lt;asp:BoundField HeaderText="Father Name" DataField="FatherName" /&gt;
          &lt;asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="AddEmployeeBasic1.aspx?thid={0}" HeaderText="Update" NavigateUrl="~/AddEmployeeBasic1.aspx" Text="Edit" /&gt;
          &lt;asp:TemplateField HeaderText="Action" ShowHeader="True"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"&gt;&lt;/asp:LinkButton&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:LinkButton runat="server" ID="lbDetail" OnClick="lbDetail_Click" DataNavigateUrlFields="Id" DataNavigateUrlFormatString="EmployeesDetails.aspx?EmpID={0}" NavigateUrl="~/EmployeesDetails.aspx" HeaderText="Show Detail" Text="Detail"&gt;&lt;/asp:LinkButton&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Here is the lbDetail_Click Code</p>
  
  <pre><code>protected void lbDetail_Click(object sender, EventArgs e)
  {
      GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
      Label lblUserName = (Label)clickedRow.FindControl("Name");
      EmployeeID.EmpName = lblUserName.ToString();
  }
  </code></pre>
  
  <p>When i put my program on Debugging mode, the lblUserName return NULL
  Here is the picture.
  <a href="https://i.stack.imgur.com/gnFXv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gnFXv.jpg" alt="enter image description here"></a></p>
  
  <p>What i want is that, when a user click on Detail LinkButton, then on lbDetail Click event, it gets the Name of the Employee and store it in a static variable. Following is the picture
  <a href="https://i.stack.imgur.com/uxkZc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uxkZc.jpg" alt="enter image description here"></a></p>
  
  <p>I don't understand how to solve this problem. Please help me through this. Your help will be really appreciated.</p>