By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

Mailto link with data from SQLDataSource

P: n/a
Hi,

I want to create a mailto link from data coming from an SQLDataSource. How
do I have to change the following code to get it working? The mailto works,
outlook starts with a new message, but the email address has not been filled
in because I don’t know how to pass the email variable into the mailto
command.

<asp:HyperLink runat="server">
<A href="mailto:">
<asp:Label ID="EmailLabel" runat="server" Text='<%# Bind("Email")
%>'></asp:Label><br />
</asp:Hyperlink>
</A>

Thanks in advance,
Regards,
Peter

Feb 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Peter,

The Bind() and Eval() functions take an optional format string that can be
used to format the data that is bound to a target property. In your case you
can format the NavigateUrl on a Hyperlink control to be something like
"mailto:ya**@xyz.com". Change your Bind(..) or Eval(..) call to
Bind("Email", "mailto:{0}"). The token {0} in the format string is replaced
the value of "Email" from your SqlDataSource.

Also, binding to SqlDataSource only works with server controls that support
Data Binding (Server controls that have a DataSourceID, such as the GridView,
FormView, DetailsView, DropDownList, CheckBoxList, BulletedList, etc.).

Here is an example of a GridView that has a bound mailto column using a
Hyperlink control.

Hope this helps,
Jason Vermillion

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Binding Using a format string">
<ItemTemplate>
<asp:HyperLink ID="lnkEmail" runat="server" NavigateUrl='<%#
Eval("Email", "mailto:{0}") %>' Text='<%# Eval("Email", "Send an Email to
{0}") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Hi,

I want to create a mailto link from data coming from an SQLDataSource. How
do I have to change the following code to get it working? The mailto works,
outlook starts with a new message, but the email address has not been filled
in because I don’t know how to pass the email variable into the mailto
command.

<asp:HyperLink runat="server">
<A href="mailto:">
<asp:Label ID="EmailLabel" runat="server" Text='<%# Bind("Email")
%>'></asp:Label><br />
</asp:Hyperlink>
</A>

Thanks in advance,
Regards,
Peter
Feb 8 '07 #2

P: n/a
Thanks a lot Jason. It works.
Regards,
Peter

"Jason Vermillion" wrote:
Peter,

The Bind() and Eval() functions take an optional format string that can be
used to format the data that is bound to a target property. In your case you
can format the NavigateUrl on a Hyperlink control to be something like
"mailto:ya**@xyz.com". Change your Bind(..) or Eval(..) call to
Bind("Email", "mailto:{0}"). The token {0} in the format string is replaced
the value of "Email" from your SqlDataSource.

Also, binding to SqlDataSource only works with server controls that support
Data Binding (Server controls that have a DataSourceID, such as the GridView,
FormView, DetailsView, DropDownList, CheckBoxList, BulletedList, etc.).

Here is an example of a GridView that has a bound mailto column using a
Hyperlink control.

Hope this helps,
Jason Vermillion

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Binding Using a format string">
<ItemTemplate>
<asp:HyperLink ID="lnkEmail" runat="server" NavigateUrl='<%#
Eval("Email", "mailto:{0}") %>' Text='<%# Eval("Email", "Send an Email to
{0}") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Hi,

I want to create a mailto link from data coming from an SQLDataSource. How
do I have to change the following code to get it working? The mailto works,
outlook starts with a new message, but the email address has not been filled
in because I don’t know how to pass the email variable into the mailto
command.

<asp:HyperLink runat="server">
<A href="mailto:">
<asp:Label ID="EmailLabel" runat="server" Text='<%# Bind("Email")
%>'></asp:Label><br />
</asp:Hyperlink>
</A>

Thanks in advance,
Regards,
Peter
Feb 8 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.