Using Mailto in ASP:HyperLink

So I wanted to add a mailto link in my code. I knew that it would be something to do with the asp:HyperLink control but was not sure how to use it. After a little testing I found this information out.

So I had pulled my email address from a SQL statement and wanted to add it to the control, this was my first attempt:

<asp:HyperLink ID="hlEmail" NavigateUrl="mailto:" Text='<%# Bind("Email") %>' runat="server"></asp:HyperLink>

This gave me a HyperLink but with a blank mailto, well that was no good. So next I got to thinking that I need to stick a Bind or Eval with the text on the NavigateUrl section:

<asp:HyperLink ID="hlEmail" NavigateUrl='mailto:<%# Bind("Email") %>' Text='<%# Bind("Email") %>' runat="server"></asp:HyperLink>

This gave me a link, but it do not work. Every time I clicked on the link nothing happened. Again I tried some more code and came up with the following:

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

This worked, so it was to do with formatting the string.  By using the in built string formatting options I was able to pass the Bind vale to the NavigateUrl parameter. Easy when you know how.