title: C#: Hyperlink in the first gridview stops working when the 2nd gridview in the same page gets populated
body: <p>I have 2 gridviews in a page. The first one gets data when the page loads and the 2nd gridview gets the data when a button is clicked. Before the 2nd gridview is populated with data, the hyperlink in the first gridview works just fine. But as soon as the button is clicked and the 2nd gridview is populated, the hyperlink in the first gridview doesn't work. Its appearance resembles a hyperlink but when I point cursor on it, it doesn't display the link nor it opens up the url. However, the hyperlinks in the 2nd gridview work fine. </p>
  
  <p><strong>Gridview whose hyperlink doesn't work after the button is clicked:</strong></p>
  
  <pre><code>&lt;asp:GridView ID="GridView2" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                  DataSourceID="Saved_Work" Style="float: left; font-size: small; position: relative;
                  width: 82%; position: relative; top: 0px; height: 55px; font-size: small; text-align: left;
                  left: 30px;" align="left"&gt;
                  &lt;Columns&gt;
                      &lt;asp:TemplateField HeaderText="ID"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:HyperLink ID="Continue_SavedWork"  runat="server" NavigateUrl='&lt;%# Eval("ID", "~/EditSavedJob.aspx?ID={0}") %&gt;'
                                  Text='&lt;%# Eval("ID") %&gt;'&gt;&lt;/asp:HyperLink&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:BoundField DataField="UserID" HeaderText="User" SortExpression="UserID" /&gt;
                      &lt;asp:BoundField DataField="Date_Created" HeaderText="Date_Created" SortExpression="Date_Created" /&gt;
                  &lt;/Columns&gt;
              &lt;/asp:GridView&gt;
  </code></pre>
  
  <p><strong>Button:</strong></p>
  
  <pre><code>&lt;asp:Button ID="Button1" runat="server" OnClick="FillGridView" Text="Search" Style="font-size: small;
                  position: relative; text-align: left; top: 0px; left: 280px; border: 1px ridge #2F10AB" /&gt;
  </code></pre>
  
  <p><strong>Gridview which gets bind on a button click:</strong></p>
  
  <pre><code>    &lt;asp:GridView ID="GridView1" runat="server" Height="27px" OnRowUpdating="EditStatus_Click"
                  Style="left: 120px; position: relative; width: 82%; top: 0px; text-align: center;
                  font-size: small;" Width="361px" AutoGenerateColumns="False"&gt;
                  &lt;Columns&gt;
                      &lt;asp:BoundField DataField="JobNumber" HeaderText="JobNumber" /&gt;
                      &lt;asp:BoundField DataField="CustomerName" HeaderText="CustomerName" /&gt;
                      &lt;asp:BoundField DataField="JobLocation" HeaderText="JobLocation" /&gt;
                      &lt;asp:BoundField DataField="StartDate" HeaderText="StartDate" DataFormatString="{0:MM/dd/yyyy}" /&gt;
                      &lt;asp:BoundField DataField="Status" HeaderText="Status" /&gt;
                      &lt;asp:TemplateField HeaderText=""&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='&lt;%# Eval("JobID", "~/JobDetails.aspx?JobID={0}") %&gt;'
                                  Text='Edit Job' /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText=""&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:HyperLink ID="Tickets" runat="server" NavigateUrl='&lt;%# string.Format("~/Tickets.aspx?JobId={0}&amp;JobNumber={1}",
      HttpUtility.UrlEncode(Eval("JobId").ToString()), HttpUtility.UrlEncode(Eval("JobNumber").ToString())) %&gt;'
                                  Text='Tickets' /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="Update Status"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:DropDownList ID="StatusDD" runat="server" Style="position: relative; font-size: small;
                                  left: 5%; font-family: 'Segoe UI'; border: 1px ridge #2F10AB; background-color: #F7F7F7"
                                  AutoPostBack="True"&gt;
                                  &lt;asp:ListItem&gt; &lt;/asp:ListItem&gt;
                                  &lt;asp:ListItem&gt;Submitted&lt;/asp:ListItem&gt;
                                  &lt;asp:ListItem&gt;Closed&lt;/asp:ListItem&gt;
                                  &lt;asp:ListItem&gt;Void&lt;/asp:ListItem&gt;
                              &lt;/asp:DropDownList&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:ButtonField ButtonType="Button" CommandName="Update" Text="Save" /&gt;
                      &lt;asp:TemplateField HeaderText="Download PDF"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;%--&lt;asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='&lt;%# Eval("JobID", "~/GeneratePDF.aspx?JobID={0}") %&gt;' Text='View' /&gt;--%&gt;
                              &lt;asp:Button ID="View" runat="server" OnClick="View_Click" Text="PDF" Style="text-align: right" /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                  &lt;/Columns&gt;
              &lt;/asp:GridView&gt;
  </code></pre>
  
  <p><strong>Server side code for the button:</strong> </p>
  
  <pre><code>protected void FillGridView(object sender, EventArgs e)
      {
          GridLabel.Enabled = true;
          GridLabel.Text = "Search Results";
          string strConnection = ConfigurationManager
                  .ConnectionStrings["test_rashmiConnectionString"].ConnectionString;
  
          using (SqlConnection con = new SqlConnection(strConnection))
          {
              SqlCommand cmd = new SqlCommand();
              cmd.Connection = con;
  
              StringBuilder sbCommand = new
                  StringBuilder("select J.JobNumber,J.Status,J.JobID,C.Name as CustomerName, C.StartDate,C.JobLocation from JobDetails J inner join CustomerDetails C on J.CustomerID=C.ID where 1=1 ");
  
              if (CustomerName.Text != "")
              {
                  sbCommand.Append(" AND C.Name=@CustomerName");
                  SqlParameter param = new
                      SqlParameter("@CustomerName", CustomerName.Text);
                  cmd.Parameters.Add(param);
              }
              if (JobNumber.Text != "")
              {
                  sbCommand.Append(" AND J.JobNumber=@JobNumber");
                  SqlParameter param = new
                      SqlParameter("@JobNumber", JobNumber.Text);
                  cmd.Parameters.Add(param);
              }
              if (FromDate.Text != "" &amp;&amp; ToDate.Text != "")
              {
                  sbCommand.Append(" AND C.StartDate between @FromDate and @ToDate");
                  SqlParameter param1 = new
                      SqlParameter("@FromDate", FromDate.Text);
                  SqlParameter param2 = new
                      SqlParameter("@ToDate", ToDate.Text);
                  cmd.Parameters.Add(param1);
                  cmd.Parameters.Add(param2);
              }
              if (JobLocation.Text != "")
              {
                  sbCommand.Append(" AND C.JobLocation= @JobLocation ");
                  SqlParameter param = new
                      SqlParameter("@JobLocation", JobLocation.Text);
                  cmd.Parameters.Add(param);
              }
              sbCommand.Append(" Order by C.StartDate desc");
  
              if (CustomerName.Text == "" &amp;&amp; JobNumber.Text == "" &amp;&amp; FromDate.Text == "" &amp;&amp; ToDate.Text == "" &amp;&amp; JobLocation.Text == "")
              {
                  sbCommand = new StringBuilder("select top 10 J.JobNumber,J.Status,J.JobID,C.Name as CustomerName, C.StartDate,C.JobLocation from JobDetails J inner join CustomerDetails C on J.CustomerID=C.ID where 1=1 Order by C.StartDate desc");
              }
  
              cmd.CommandText = sbCommand.ToString();
              cmd.CommandType = CommandType.Text;
              con.Open();
              SqlDataReader rdr  = cmd.ExecuteReader();
              GridView1.DataSource = rdr;          
              GridView1.DataBind();
  
              GridView2.DataSource = Saved_Work;
              GridView2.DataBind();
          }
      }
  </code></pre>