how to use Eval with mailto?

A

Arvan

hi,all.

i wanna use Eval("DataField") to bind datarow in item template of GridView.

for example:
<asp:Label runat="server" id="Label1" text='<%# Eval("DataField")
%>'><asp:Label>

but how to use eval with control HyperLink?

<asp:HyperLink runat="server" id="email" NavigateUrl='mailto:<%#
Eval("Email") %>'>Email</asp:HyperLink>

Please watch property NavigateUrl.when i use mailto,there is no syntax
error.but i debug it , i saw that hyperlink's navigateurl didn't bind
datafield Email.how to use eval with mailto?
 
N

Nathan Sokalski

When you want the output of an Eval to be something other than the exact
data from the datasource, do something like this:


<asp:HyperLink id="lnkEmail" runat="server" text='<%#
DataBinder.Eval(Container, "DataItem.email") %>' NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}")
%>'></asp:HyperLink>


Notice that in the Eval used in the NavigateUrl there are three parameters:

Container (this will always be the same, do not change it)
"DataItem.email"
"MAILTO:{0}"

In the last parameter, create a string which formats the output. Place {0}
wherever you want the data from the datasource to appear. For example, in my
example, you would get something like:

MAILTO:[email protected]

For more detail, see the documentation. If you have any questions, feel free
to ask and I will do my best to help. Good Luck!
 
A

Arvan

Thank you very much!!!

Nathan Sokalski said:
When you want the output of an Eval to be something other than the exact
data from the datasource, do something like this:


<asp:HyperLink id="lnkEmail" runat="server" text='<%#
DataBinder.Eval(Container, "DataItem.email") %>' NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}")
%>'></asp:HyperLink>


Notice that in the Eval used in the NavigateUrl there are three
parameters:

Container (this will always be the same, do not change it)
"DataItem.email"
"MAILTO:{0}"

In the last parameter, create a string which formats the output. Place {0}
wherever you want the data from the datasource to appear. For example, in
my example, you would get something like:

MAILTO:[email protected]

For more detail, see the documentation. If you have any questions, feel
free to ask and I will do my best to help. Good Luck!
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top