Blog of a Filipino Developer about C#, VB.NET, ASP.NET, Java, PHP, SQL Server, MySql and Oracle RSS 2.0
 Wednesday, November 07, 2007

I was reading my site refferers today when I saw an interesting refferer query that came from Google. Three people got to my site after typing this phrase "hyperlink databind gridview mailto". I went to the the Google results page and immediately went to the page the was indexed by Google and upon futher review i found that my page wasn't really the answer to those persons question. Out of my curiousity i fired Visual Studio 2005 up and tried to add mailto link to a GridView using the HyperlinkField as my base.

<asp:HyperLinkField  DataNavigateUrlFields="Email" 
                     DataNavigateUrlFormatString="mailto:{0}"
                     DataTextField="Email" Text="Email me!" />

I ran the project thinking that this should work because this always works for me when i do same process for URLs. To my surprise, it didn't. For some unknown reason the column appears as plain text without any href attribute in sight. I went back to the HTML and checked it twice to see if maybe i missed something on the control attributes... hmmm, eveything looks ok. After a few minutes of playing around I resorted to the technique that never fails.. I converted the column to a TemplateField.

<asp:TemplateField HeaderText="Email">
   <ItemTemplate>
      <asp:HyperLink ID="emailHyperLink" 
                     runat="server" 
                     NavigateUrl='<%# Eval("Email", "mailto:{0}") %>'
                     Text='<%# Eval("Email") %>' />
   </ItemTemplate>
</asp:TemplateField>

Run the project again and sure enough, it worked. Huh! Weird! Anybody who knows what happened?

Wednesday, November 07, 2007 12:02:15 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET
Comments are closed.
On this page
Archive
<December 2008>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Keith Rull
Sign In
Statistics
Total Posts: 260
This Year: 57
This Month: 0
This Week: 0
Comments: 116
Themes
Pick a theme:
Ads
All Content © 2008, Keith Rull
DasBlog theme 'Business' created by Christoph De Baene (delarou)