views:

122

answers:

1

I have datacolumn in my gridview that has either a url, or plain text. How do I toggle a Hyperlink in the HTML?

This is what I have so far... which returns "View Link..." with or without a url :(

<ItemTemplate>
     <asp:HyperLink ID="HyperLink3" runat="server" Text="View Link..." NavigateUrl='<%# Bind("DocLink") %>' Target="_blank"></asp:HyperLink>
     <asp:Label ID="Label8" runat="server" Text='<%# Bind("Details") %>'></asp:Label>
</ItemTemplate>
+2  A: 

I'm not sure I understand your question, but if you are trying to selectively show or hide one of the controls in your ItemTemplate depending on the data, use the OnItemDataBound event, use FindControl() to get the controls, and set the Visible property on each appropriately.

If your logic for Visible is relatively simple, you can add it right to your ItemTemplate. Something like:

Visible='<%# ((System.Data.DataRowView)Container.DataItem)["DocLink"] != System.DBNull.Value %>'
Dave