title: ASP.NET Gridview ItemTemplate Access in CodeBehind
body: <p>I am having trouble accessing an asp.NET HiddenField from a Gridview ItemTemplate in the codebehind. I need to be able to read the values that these hiddenfields contain so that I can execute the delete method.
   The code is as follows</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="MemberList.ascx.cs" Inherits="UserControls_MemberList" %&gt;
  &lt;asp:RadioButtonList ID="ReportSelect" runat="server" RepeatDirection="Horizontal"&gt;
  &lt;asp:ListItem Value="1"&gt;All&lt;/asp:ListItem&gt;
  &lt;asp:ListItem Value="2"&gt;Current Members&lt;/asp:ListItem&gt;
  &lt;asp:ListItem Value="3"&gt;Perspective Members&lt;/asp:ListItem&gt;
  &lt;/asp:RadioButtonList&gt;
  &lt;asp:Button ID="ReportSelectButton" runat="server" OnClick="ReportSelectButton_Click"
  Text="Select Report Type" /&gt;
  &lt;asp:Button ID="LinkToHomePage" runat="server" Text="Back to Homepage" OnClick="LinkToHomePage_Click"&gt;
  &lt;/asp:Button&gt;
  &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Height="308px"
  Width="1282px" onselectedindexchanged="GridView1_SelectedIndexChanged"&gt;
  &lt;Columns&gt;
      &lt;asp:BoundField HeaderText="First Name" AccessibleHeaderText="FirstName" DataField="FirstName"&gt;
      &lt;/asp:BoundField&gt;
      &lt;asp:BoundField HeaderText="Last Name" AccessibleHeaderText="LastName" DataField="LastName"&gt;
      &lt;/asp:BoundField&gt;
      &lt;asp:BoundField HeaderText="Street Address" AccessibleHeaderText="StreetAddress"
          DataField="StreetAddress"&gt;&lt;/asp:BoundField&gt;
      &lt;asp:BoundField HeaderText="City" AccessibleHeaderText="City" DataField="City"&gt;&lt;/asp:BoundField&gt;
      &lt;asp:BoundField HeaderText="State" AccessibleHeaderText="State" DataField="State"&gt;
      &lt;/asp:BoundField&gt;
      &lt;asp:BoundField HeaderText="Zip" AccessibleHeaderText="Zip" DataField="Zip"&gt;&lt;/asp:BoundField&gt;
      &lt;asp:BoundField HeaderText="Birthday" AccessibleHeaderText="Birthday" DataField="Birthday" /&gt;
      &lt;asp:BoundField HeaderText="Email" AccessibleHeaderText="Email" DataField="Email"&gt;
      &lt;/asp:BoundField&gt;
      &lt;asp:BoundField HeaderText="PrimaryPhone" AccessibleHeaderText="PrimaryPhone" DataField="PrimaryPhone" /&gt;
      &lt;asp:BoundField HeaderText="AlternatePhone" AccessibleHeaderText="AlternatePhone"
          DataField="AlternatePhone" /&gt;
      &lt;asp:BoundField HeaderText="Pending" AccessibleHeaderText="Pending" DataField="Pending" /&gt;
      &lt;asp:BoundField HeaderText="IsMember" AccessibleHeaderText="IsMember" DataField="IsMember" /&gt;
      &lt;asp:BoundField HeaderText="Username" AccessibleHeaderText="Username" DataField="Username"&gt;
      &lt;/asp:BoundField&gt;
      &lt;asp:BoundField HeaderText="Description" AccessibleHeaderText="Descripton" DataField="Description" /&gt;
      &lt;asp:TemplateField HeaderText="Edit" AccessibleHeaderText="Edit"&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:HyperLink ID="EditUsername" runat="server" NavigateUrl='&lt;%# Link.ToMemberAdmin(Eval("Username").ToString())%&gt;'
                  Text="Edit" /&gt;
              &lt;asp:Button ID="DeleteButton" runat="server" Text="Delete Entry" OnClick="DeleteButton_Click"/&gt;
              &lt;asp:HiddenField ID="HiddenUsername" Value='&lt;%#Bind("Username") %&gt;' runat="server" /&gt;
              &lt;asp:HiddenField ID="HiddenEmail" Value='&lt;%#Bind("Email") %&gt;' runat="server" /&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>CodeBehind</p>
  
  <pre><code>protected void DeleteButton_Click(object sender, EventArgs e)
  {
      HiddenField Username = GridView1.FindControl("HidderUsername") as HiddenField;
      HiddenField Email = GridView1.FindControl("HiddenEmail") as HiddenField;
      string username = Username.Value;
      string email = Email.Value;
      AdminAccess.DeleteMemberApplication(username, email);
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>