Gridview - hyperlink to an email column

  • Thread starter Thread starter HRsoft Informática
  • Start date Start date
H

HRsoft Informática

ASP.NET 3.5 / VWD express 2008

Gridview, dynamically created and populated.
All the coluns are created dynamically, like this:

..........................
Dim coluna11 As New BoundField
...............
coluna11.DataField = "s_email"
coluna11.HeaderText = "Email"
coluna11.ItemStyle.Wrap = False

GridHistorico.Columns.Clear()
GridHistorico.Columns.Add(coluna11)
etc....

I need this column, an email, hyperlinked like: mailto:(the content of the
column)

Thanks in advance
 
Thanks for your response. But I need to create dynamically, on .VB 2008. I
try this:

Dim coluna11 As New HyperLinkField

coluna11.DataTextField = "s_email"
coluna11.HeaderText = "Email"
coluna11.Text = "<%# Eval('s_Email') %>"
coluna11.NavigateUrl = "<%# Eval('s_Email', 'mailto:{0}') %>"
'coluna11.DataNavigateUrlFields = "s_email"
coluna11.ItemStyle.Wrap = False

With this code, the content of the column change color to hyperlink color (
according to .CSS), but no redirect or link to outlook, etc, ie, nothing
happens.

--
Hércules
HRsoft Informática - Rio de Janeiro - Brasil
http://www.hrsoft.com.br
 
Hi,

According to the mentioned blog You can try something like this:

GridView gv = new GridView() { AutoGenerateColumns = false };
Page.Form.Controls.Add(gv);
var list = new[]
{
new {Name = "John Smith", EMail = "(e-mail address removed)"},
new {Name = "John Doe", EMail = "(e-mail address removed)"},
new {Name = "Jane Doe", EMail = "(e-mail address removed)"}
};
BoundField f1 = new BoundField() { DataField = "Name",
HeaderText = "Name" };
TemplateField f2 = new TemplateField();
f2.ItemTemplate = Page.LoadTemplate("EMailTemplate.ascx");
f2.HeaderText = "e-mail";
gv.Columns.Clear();
gv.Columns.Add(f1);
gv.Columns.Add(f2);
gv.DataSource = list;
gv.DataBind();


Also create a web user control EMailTemplate, and put the hyperlink field
into it (see below)
(the Control tag might differ according Your application name)
--------------------------------------- Contents of EMailTemplate.ascx

<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="EMailTemplate.ascx.cs"
Inherits="YourWebApplication.EMailTemplate" %>

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

Hope You find this useful.
-Zsolt
 
Back
Top