how to use Eval with mailto?

  • Thread starter Thread starter Arvan
  • Start date Start date
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?
 
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!
 
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!
 
Back
Top