Gridview - hyperlink to an email column

Discussion in 'ASP .Net' started by HRsoft Informática, Jan 29, 2009.

  1. 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
    --
    Hércules
    HRsoft Informática - Rio de Janeiro - Brasil
    http://www.hrsoft.com.br
     
    HRsoft Informática, Jan 29, 2009
    #1
    1. Advertising

  2. 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



    "Mark Rae [MVP]" wrote:

    > "HRsoft Informática" <> wrote in
    > message news:...
    >
    > > I need this column, an email, hyperlinked like: mailto:(the content of the
    > > column)

    >
    > http://dotnetspidor.blogspot.com/2008/10/mailto-formatted-email-address-in.html
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    HRsoft Informática, Jan 29, 2009
    #2
    1. Advertising

  3. HRsoft Informática

    miher Guest

    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 = ""},
    new {Name = "John Doe", EMail = ""},
    new {Name = "Jane Doe", EMail = ""}
    };
    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


    "HRsoft Informática" <> wrote in
    message news:...
    > 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
    >
    >
    >
    > "Mark Rae [MVP]" wrote:
    >
    >> "HRsoft Informática" <> wrote
    >> in
    >> message news:...
    >>
    >> > I need this column, an email, hyperlinked like: mailto:(the content of
    >> > the
    >> > column)

    >>
    >> http://dotnetspidor.blogspot.com/2008/10/mailto-formatted-email-address-in.html
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net
    >>
    >>
     
    miher, Jan 29, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?V2FyYW4=?=

    HyperLink Column and Button Column in a DataGrid

    =?Utf-8?B?V2FyYW4=?=, Aug 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    621
    =?Utf-8?B?V2FyYW4=?=
    Aug 9, 2005
  2. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    11
    Views:
    1,022
    deandany
    Jul 17, 2006
  3. davetichenor
    Replies:
    1
    Views:
    884
    Eliyahu Goldin
    Oct 30, 2006
  4. Keith G Hicks
    Replies:
    3
    Views:
    793
    Keith G Hicks
    Feb 18, 2008
  5. Dave
    Replies:
    0
    Views:
    978
Loading...

Share This Page