0

I am trying to open a mailto that will use the emailaddress from the databound field and add a custom subject line and custom body.

My mailto window pops up and the email address specific to the data field is populated, however the subject and the body remain empty.

<asp:BoundField DataField="EmailAddress" HeaderText="Refer Patient" 
   SortExpression="EmailAddress" 
   DataFormatString="<a href=mailto:{0}&gt;{0}&lt;?subject=Email%20Subject&body=Email%20Body%20Text >  </a>" 
   HtmlEncode="false" 
   HtmlEncodeFormatString="false"  /> 

Any suggestions on where I am going wrong?

Donncha
  • 43
  • 1
  • 7

2 Answers2

1

You have invalid HTML, your HTML href attribute value is not wrapped in quotes, try this:

<asp:BoundField DataField="EmailAddress" HeaderText="Refer Patient" 
   SortExpression="EmailAddress" 
   DataFormatString='<a href="mailto:{0}&gt;{0}&lt;?subject=Email%20Subject&body=Email%20Body%20Text">Email Me</a>' 
   HtmlEncode="false" 
   HtmlEncodeFormatString="false"  /> 
Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
1

You can switch to TemplateField, then you have much more control over the generated HTML.

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <a href="mailto:<%# Eval("EmailAddress") %>?subject=Email%20Subject&body=Email%20Body%20Text">Email Me</a>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
VDWWD
  • 35,079
  • 22
  • 62
  • 79