views:

1191

answers:

1

I wish there was a ToolTip field in HyperLinkField as there is one in HyperLink. I'm creating a HyperLinkField by code before binding to my data source:

HyperLinkField hl = new HyperLinkField(); 
hl.DataNavigateUrlFields = new string[] { "col" };
hl.DataNavigateUrlFormatString = "{0}";
hl.DataTextField = "Foo";

Is there any way to also set a value to something which will render as a tooltip (or alt text)? Any help will be appreciated.

+6  A: 

That's correct, there's no tooltip/alt text property in a HyperlinkField. To get around this shortcoming, you need to use a template field and add a regular Hyperlink control.

<asp:TemplateField HeaderText="Href">
    <ItemTemplate>
       <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#
          Eval("Href") %>' Text='<%# Eval("Href") %>' ToolTip='<%# Eval("Text")         %>'> 
       </asp:HyperLink>
    </ItemTemplate>
</asp:TemplateField>

However, doing this in a programmatic requires a lot of work. You need to create your own class that implements the ITemplate interface. Here's a tutorial on that.

Jose Basilio
When you copy code off of a web page, you should be providing a link to that web page.
womp
I really hoped to avoid this, but thanks...