Making an email link with DataBinder.Eval

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I want to make an email link using databinding. I am able to get and display
the email address from the database it is stored in using databinding as
follows:

<asp:HyperLink id="lnkEmail1" runat="server" NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.email") %>' Target="_blank"><%#
DataBinder.Eval(Container, "DataItem.email") %></asp:HyperLink>

However, you will notice that because the NavigateUrl attribute is the same
as the displayed text (I did not add the MAILTO:) the browser interprets it
as a URL. When I try to add the MAILTO: I recieve a runtime error. How do I
fix this so that the NavigateUrl attribute starts with MAILTO: like I want
it to? Thanks.
 
Hi,

Take a look at this version of databinder.eval. Untested

http://msdn.microsoft.com/library/d...frlrfsystemwebuidatabinderclassevaltopic2.asp

<asp:HyperLink id="lnkEmail1" runat="server" NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.email", "MailTo:{0}") %>'
Target="_blank"><%# DataBinder.Eval(Container, "DataItem.email")
%></asp:HyperLink>

Ken
---------------------------
I want to make an email link using databinding. I am able to get and display
the email address from the database it is stored in using databinding as
follows:

<asp:HyperLink id="lnkEmail1" runat="server" NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.email") %>' Target="_blank"><%#
DataBinder.Eval(Container, "DataItem.email") %></asp:HyperLink>

However, you will notice that because the NavigateUrl attribute is the same
as the displayed text (I did not add the MAILTO:) the browser interprets it
as a URL. When I try to add the MAILTO: I recieve a runtime error. How do I
fix this so that the NavigateUrl attribute starts with MAILTO: like I want
it to? Thanks.
 
Back
Top