title: How to enable and disable the hyperlink in gridview?
body: <p>I have a hyperlink in the template field. I want to enable and disable the hyperlink based on its value. Let's say if <code>Id</code> is <code>"ABC"</code> I want to disable the hyperlink. I tried the code below but it didnt work for me.</p>
  
  <pre><code>Enabled='&lt;%# Convert.ToString(Eval("Id"))!= "ABC" ? true: false %&gt;'
  </code></pre>
  
  <p>I tried the following in the code behind:</p>
  
  <pre><code>protected void gridResult_RowDataBound(object sender, GridViewRowEventArgs e) { 
      if (e.Row.RowType == DataControlRowType.DataRow)
      {  
          HyperLink status = (HyperLink)e.Row.Cells[2].Controls[0];
          if (status != null &amp;&amp; status.Text == "ABC") {
              status.Enabled = false; 
          }
      }
  }
  </code></pre>
  
  <p>But it is returning <code>null</code> every time.</p>
  
  <pre><code>    &lt;asp:TemplateField HeaderText="Id"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;% if ( WebApp.Common.Auth.Admin() ) { %&gt;
                                  &lt;a href="../../Edit/Default.aspx?&lt;%= WebApp.Edit.Default.P_ID %&gt;=&lt;%# DataBinder.Eval(Container.DataItem, "Id") %&gt;&amp;amp;r=&lt;%= buildPostBackPortion() %&gt;"&gt;&lt;%# DataBinder.Eval(Container.DataItem, "Id") %&gt; Enabled='&lt;%# Convert.ToString(Eval("Id"))!= "ABC" ? true: false %&gt;'
  &lt;/a&gt;
                              &lt;% } else { %&gt;
                                  &lt;%# DataBinder.Eval(Container.DataItem, "Id") %&gt;
                              &lt;% } %&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  </code></pre>