MailTo in a GridView

Just a little tip since I had to Google it.  How do you make a column in a gridview show an e-mail address as a link that does a mailto:?

image

image

You’d think you could do a HyperLink column, but for some reason it doesn’t like the colon in the URL.  So instead you make a Bound Field and control the output to render the Anchor tag:

            <asp:BoundField DataField=”Email”
               
HeaderText=”Email”
               
DataFormatString=”&lt;a href=mailto:{0}&gt;{0}&lt;/a&gt;”
               
HtmlEncodeFormatString=”false”
               
SortExpression=”Email” />

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s