MailTo Hyperlink in Gridview

S

Stuart Ferguson

I am currently writing an application in ASP.Net which has a bound
Gridview however i require to add a column with a mailto link in it.
After many questions in the c# IRC room it was decided that a templat
column was the best way which i have put in and the basic mailto a bound
address is file however i want to add to the mailto link a subject and
some other info, how do i go about this? I know how its done in standard
HTML but in this case i am using the binding of the Hyperlink and im not
sure how to do it using the DataBinder expressions. Any help is
appreciated.

Many Thanks In Advance

Stuart
 
S

Stuart Ferguson

Thanks for answering so quickly srini.

WIll this example be valid for ASP.NET 2.0 (shud have mentioned this in
original question)

Best Wishes

Stuart
 
G

Guest

Hi,
I didnt check on ASP.Net 2.0 but it should work without any problem.. just
use the code in the webform1.aspx.cs if u have problems opening or running
the project.
 
Joined
Oct 18, 2007
Messages
2
Reaction score
0
Email subject in gridview

Here is the code for including the subject in your code in a detailsview of GridView in 2.0

<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:HyperLink ID="EmailLink" text='<%# Bind("job_email") %>' NavigateUrl='<%# Eval("job_email","mailto:{0}?Subject=Career/Employment Inquiry")%>' runat="server" target="_blank" />
</ItemTemplate>
</asp:TemplateField>

Job_email is pulled from a SQL query in this case
 
Joined
Nov 26, 2007
Messages
1
Reaction score
0
MailTo Hyperlink in Gridview without template field

I have had the same problem but found a quick way to work around it.

Simply use the DataTextField and DataTextFormatString properties instead. The DataTextFormatString would be something similar to DataTextFormatString="<a href=mailto:{0}>{0}</a>" instead of the DataNavigateUrlFormatString property.

<asp:HyperLinkField HeaderText="Email" DataTextField="Email" DataTextFormatString="<a href=mailto:{0}>{0}</a>" />

Hope this helps.
-Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top