Tuesday, July 10, 2012

Adding an email link to a field contained in a GridView control

The following code sample provides a simple way to add a hyperlink to your GridView control that will launch the user's email client when the user clicks on the link.  In this case, you'll want to focus on the second BoundField control which creates the mailto hyperlink:

<asp:GridView ID="gridViewSiteAdmins" AutoGenerateColumns="false" runat="server"
    EnableModelValidation="True" >
    <Columns>
        <asp:BoundField HeaderText="Name" DataField="Name" />
        <asp:BoundField HeaderText="Email" DataField="Email" DataFormatString="<a href=mailto:{0}>{0}</a>" HtmlEncodeFormatString="false" />
    </Columns>
</asp:GridView>

By the way, there are other routes you can use to do this, but I thought I'd at least give you one that works well for me.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.