mailto link in GridView

If you add a HyperLinkField to a Grid View and you set the DataNavigateUrlFields to “Email” (the field coming from the database) and the DataNavigateUrlFormat to “mailto:{0}” it wont work, because asp.net does some extra validation and the output is no link.

The only way to have an email link inside a GridView is by using a TemplateField

Use this code to generate the TemplateField:

 

<asp:TemplateField HeaderText=“Email”>
<ItemTemplate>
<asp:HyperLink ID=“emailHyperLink” runat=“server” NavigateUrl=<%# Eval(“Email”, “mailto:{0}”) %>
Text=<%# Eval(“Email”) %> Target=“_blank”></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>

Fii primul care comenteaza scris de Catalin Radoi
17 Jun/2009

Comenteaza



rss