title: Select a row in GridView and pass the record id to the redirected page
body: <p>I've been struggling with this issue for a whole day now and I don't seem to find an answer.</p>
  
  <p>I have a page called PickRecord.aspx where I have dynamically generated columns "Start Interview", "Edit" and "View Record" which will redirect me to the StartInterview.aspx or EditViewInterview.aspx accordingly.</p>
  
  <p>PickRecord.aspx - The GridView is populated with Interviewee names and a button is generated which when clicked on should redirect me to StartInterview.aspx and give me other fields/information in the record selected.</p>
  
  <p>StartInterview.aspx - Contains additional information on the record chosen which needs to be populated with data from the database. I have tried query string, used selectedIndexChanged and had no luck.</p>
  
  <p>Woul'd really appreciate it if somebody can guide me through this. Thanks in advance!</p>
  
  <pre><code>PickRecord.aspx
  
  
  &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="470px" Width="660px" HorizontalAlign="Center" SelectedIndexChanged="GridView1_SelectedIndexChanged"&gt;
  
      &lt;Columns&gt;   
          &lt;asp:BoundField DataField="First_Name" HeaderText="First Name" ItemStyle-HorizontalAlign = "Center"&gt;    
          &lt;/asp:BoundField&gt;   
  
          &lt;asp:BoundField DataField="Last_Name" HeaderText=" Last Name" ItemStyle-HorizontalAlign = "Center" &gt;    
          &lt;/asp:BoundField&gt;   
  
          &lt;asp:BoundField DataField="Salon_Number" HeaderText="Salon" ItemStyle-HorizontalAlign = "Center" &gt;  
          &lt;/asp:BoundField&gt;   
  
      &lt;/Columns&gt;  
  &lt;/asp:GridView&gt; 
  </code></pre>
  
  <p>
     </p>
  
  <p>PickRecord.aspx.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.IO;
  using System.Data.SqlClient;
  using System.Data;
  
  namespace TSS.Trainer
  {
  
      public partial class Trainer_PickRecord : System.Web.UI.Page
      {
      static string id;
  
  
      protected void Page_Load(object sender, EventArgs e)
      {
          dbConnection dbConn = new dbConnection();
          string s = Request.QueryString["mode"].ToString();
  
          if (!IsPostBack)
          {
              FillMonth(ddl_T_month);
              FillYear(ddl_T_year);
          }
  
          if (s == "a")
          {
  
              TemplateField tf1 = new TemplateField();
              tf1.ItemTemplate = new btntemplate1();
              tf1.HeaderText = "Start Interview";
              tf1.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
              GridView1.Columns.Add(tf1);
  
              DataTable dtInterviewee = new DataTable();
              dtInterviewee = Salon_WebService.populateInterviewee();
              GridView1.DataSource = dtInterviewee;
              GridView1.DataBind();
          }
  
          else if (s == "b")
          {
              TemplateField tf2 = new TemplateField();
              TemplateField tf3 = new TemplateField();
              tf2.ItemTemplate = new btntemplate2();
              tf3.ItemTemplate = new btntemplate3();
              tf2.HeaderText = "Edit";
              tf3.HeaderText = "View";
              tf2.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
              tf3.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
              GridView1.Columns.Add(tf2);
              GridView1.Columns.Add(tf3);
  
              DataTable dtInterviewee = new DataTable();
              dtInterviewee = Salon_WebService.populateInterviewee();
              GridView1.DataSource = dtInterviewee;
              GridView1.DataBind();
          }
  
           void GridView1_SelectedIndexChanged(object sender, EventArgs e)
           {
              GridViewRow row = GridView1.SelectedRow;
              id = row.Cells[0].Text;
           }
  
      }
  
  
  
      class btntemplate1 : ITemplate
      {
  
          public void InstantiateIn(System.Web.UI.Control container)
          {
  
              HyperLink h1 = new HyperLink();
              h1.NavigateUrl = "Trainer_StartInterview.aspx?x= " +id;
              h1.ImageUrl = "../Images/T_StartIV_small.png";
              container.Controls.Add(h1);
          }
      }
  
  
      class btntemplate2 : ITemplate
      {
          public void InstantiateIn(System.Web.UI.Control container)
          {
  
              HyperLink h2 = new HyperLink();
              h2.NavigateUrl = "Trainer_Home.aspx";
              h2.ImageUrl = "../Images/Edit_small.png";
  
              container.Controls.Add(h2);
  
          }
      }
  
      class btntemplate3 : ITemplate
      {
          public void InstantiateIn(System.Web.UI.Control container)
          {
              HyperLink h3 = new HyperLink();
              h3.NavigateUrl = "Trainer_ViewRecord.aspx";
              h3.ImageUrl = "../Images/View_small.png";
  
              container.Controls.Add(h3);
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>StartInterview.aspx</p>
  
  <pre><code>&lt;div id="T_StartInterview_formHeader" class="fh2"&gt;
          &lt;center&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblCreate_Date" runat="server" Text="Create Date : "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="LabelCD" runat="server" Text="December 05, 2011 "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblUpdate_Date" runat="server" Text="Update Date : "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="lblUD" runat="server" Text="December 09, 2011 "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblCreatedBy" runat="server" Text="Created By : "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="lblCB" runat="server" Text='&lt;%# Eval ("First_Name") %&gt;' class="lblSizeR"&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblUpBy" runat="server" Text="Updated By : "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="lblUB" runat="server" Text="Sharon Miller " class="lblSizeR"&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblFName" runat="server" Text="First Name : "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="lblFN" runat="server" Text="Michelle"&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblLName" runat="server" Text="Last Name : "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="lblLN" runat="server" Text="Rusk"&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblPhone" runat="server" Text="Phone : "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="lblPh" runat="server" Text="269 123 1234"&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblEmail" runat="server" Text="E-Mail : "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="lblMail" runat="server" Text="xyz@visiblechanges.com" class="lblSizeR"&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td style="text-align: right; color: white"&gt;
                          &lt;asp:Label ID="lblSalon" runat="server" Text="Salon: "&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="lblSal" runat="server" Text="Memorial City Mall" class="lblSizeR"&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
  </code></pre>
  
  <p>Trainer_StartInterview.aspx.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  namespace TSS.Trainer
  {
  public partial class Trainer_StartInterview : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          string s = Request.QueryString["id"].ToString();
      }
  }
  </code></pre>
  
  <p>}</p>