Thursday, January 24, 2008

Gridview hyperlinkfield

When you use hyperlinkfield like the following, the link for email actually becomes unclickable.

<asp:gridview id="SearchResults" autogeneratecolumns="false" datakeynames="vbpk_intUserID" runat="server">

<columns>

<asp:hyperlinkfield datatextfield="strEmail" datanavigateurlfields="strEmail" datanavigateurlformatstring="mailto:{0}" headertext="Email" target="_blank" />

</columns>

</asp:gridview>


So you have to use TemplateField to solve the problem:


<asp:gridview id="SearchResults" autogeneratecolumns="false" datakeynames="vbpk_intUserID" runat="server">

<columns>

<asp:TemplateField HeaderText="Email">

<ItemTemplate>

<asp:HyperLink runat="server" Text='<%# Eval("strEmail") %>' NavigateUrl='<%# Eval("strEmail", "mailto:{0}") %>' ID="hlEmail"/>

</ItemTemplate>

</asp:TemplateField>

</columns>

</asp:gridview>

Displaying a Formatted Email Addresses in a GridView or DetailsView

blog comments powered by Disqus