title: Set and retrieve value from HiddenField in Gridview
body: <p>I have a custom control that is embedded in a <code>GridView</code>.  The control needs a value (Id column from SqlDataSource1) contained in the same data table that the gridview is bound to for its constructor.</p>
  
  <p>The problem I'm having is that I don't understand how to set the value of the hidden field.  The data type is for this field is a Guid.  </p>
  
  <p><strong>ASPX</strong>:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridUserControl.ascx.cs" Inherits="CustomNavi_V1_ControlTest.CustomControls.GridUserControl" %&gt;
  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:srsfwa1_scrambledConnectionString %&gt;" SelectCommand="SELECT [ApplicantId], [ValleyId], [SchoolId], [StatusId], [StudentID], [InterviewDate], [Id] FROM [tblSubmissions]"&gt;&lt;/asp:SqlDataSource&gt;
  &lt;asp:GridView ID="StudentGridView" DataKeysNames="Submission" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnDataBound ="StudentGridView_OnDataBind"&gt;
  &lt;Columns&gt;
      &lt;asp:BoundField DataField="ApplicantId" HeaderText="ApplicantId" SortExpression="ApplicantId" /&gt;
      &lt;asp:BoundField DataField="ValleyId" HeaderText="ValleyId" SortExpression="ValleyId" /&gt;
      &lt;asp:BoundField DataField="SchoolId" HeaderText="SchoolId" SortExpression="SchoolId" /&gt;
      &lt;asp:BoundField DataField="StudentID" HeaderText="StudentID" SortExpression="StudentID" /&gt;
      &lt;asp:BoundField DataField="InterviewDate" HeaderText="InterviewDate" SortExpression="InterviewDate" /&gt;
      &lt;asp:BoundField DataField="StatusId" HeaderText="StatusId" SortExpression="StatusId" visible="true"/&gt;
      &lt;asp:BoundField DataField="Id" Visible ="false" /&gt;
      &lt;asp:TemplateField&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:HiddenField ID="HiddenField" DataField="SubmissionID" runat="server" Value=""/&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
      &lt;asp:TemplateField Visible="true" HeaderText="Ed's Fabulous Custom Control!!" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"&gt;
          &lt;ItemTemplate&gt;
  
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
  
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p><code>HiddenField</code>:</p>
  
  <pre><code>protected void AddCustomControl()
  {
      int iterator = 0;
      foreach (GridViewRow row in StudentGridView.Rows)
      {
          if (row.RowType == DataControlRowType.DataRow)
          {
              //StudentGridView.HiddenField.value= StudentGridView.
              //HiddenField hiddenField = this.StudentGridView1.FindControl("
              Guid submissionIdGuid = (Guid)hiddenField.Value; // ("SubmissionID").Value;
              string controlID = "NavigatorControlID" + iterator.ToString();
              string submissionID = row.Cells[6].Text;  // tblSubmissions Id field
              string statusId = row.Cells[5].Text; // tblSubmissions StatusId field
              connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["srsfwa1_scrambledConnectionString"].ToString());
  
              CustomNavi_V1._1.CustomNavi_V1 navigator = new CustomNavi_V1._1.CustomNavi_V1(submissionID, statusId);
              navigator.ID = controlID;
              navigator.SubmissionID = submissionIdGuid;
              navigator.BackButtonImage = "Images/back_button.png";
              navigator.ForwardButtonImage = "Images/fwd_button.png";
  
              row.Cells[7].Controls.Add(navigator);
              iterator++;
          }
      }
  }
  </code></pre>