Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting hyperlink object out of the RowDataBound event
    primarykey
    data
    text
    <p>I need to programmatically disable certain hyperlinks in a gridview based upon the value of another column in the row. I decided to handle the OnRowDataBound event to iterate and set them at runtime. This mostly works, except I need to get to the HyperLink object. How can I do it? </p> <p>Here's where I'm at</p> <pre><code> protected void IncomingTransfersGv_RowDataBound(object sender, GridViewRowEventArgs e) { // COLUMN OFFSET IN USE if (e.Row.RowType == DataControlRowType.DataRow) { object[] dataitems = ((DataRowView)e.Row.DataItem).Row.ItemArray; string carrier = (string)dataitems[7].ToString(); if (carrier.ToLower() == "hand") (dataitems[8] as HyperLink).Enabled = false;//How can I get the hyperlink object here? dataitems[8] only gives me the column's value..I don't need this } } </code></pre> <p><strong>UPDATE</strong> The conversions aren't working. I get an error about cannot convert type TableCell to Hyperlink. HyperLinkField doesn't have an ID attribute. Per an <a href="http://www.codenewsgroups.net/aspnetwebcontrols/t9795-hyperlinkfield-findcontrol.aspx" rel="nofollow">article</a>, I changed the hyperlinkfield to a template field, which is supposed to make this easier somehow, but unfortunetly the article doesn't say how...any ideas?</p> <pre><code> &lt;asp:TemplateField HeaderText="Tracking"&gt; &lt;ItemTemplate&gt; &lt;asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='&lt;%# Eval("trackingUrl", "{0}") %&gt;' Text='&lt;%# Eval("trackingNumber", "{0}") %&gt;'&gt;&lt;/asp:HyperLink&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload