title: How to programmatically replace an HyperLinkField in a ASP.NET GridView
body: <p>I have an ASP.NET Web Forms application. In my application I have a <strong>GridView</strong> that works smoothly. I have several text fields and the last one is a <code>&lt;asp:hyperlinkfield&gt;</code>.</p>
  
  <p>Now I would like to programmatically change the field by placing a <strong>simple link</strong> instead of the <code>hyperlinkfield</code> if a specific condition is fulfilled. Therefore I catch the <code>onRowDataBound</code> event:</p>
  
  <pre><code>Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles myGridView.RowDataBound
  
      If (condition) Then
             Dim link = New HyperLink()
             link.Text = "login"
             link.NavigateUrl = "login.aspx"
             e.Row.Cells(3).Controls.Add(link)
          End If
      End If
  End Sub
  </code></pre>
  
  <p>where <strong>n</strong> is the cell where the <code>hyperlinkfield</code> is placed. With this code it just adds to the <code>hyperlinkfield</code> the new <code>link</code>. How can I replace it?</p>
  
  <p>PS: The code is in VB6 but I am a C# programmer, answers with both languages are accepted</p>