asp:hyperLink NavigateURL and Eval functions

2020-04-29 14:05发布

问题:

What is the correct syntax to add a Eval() function to the NavigateURL attribute of asp:HyperLink?

I am trying to achieve the below:

NavigateUrl="http://home/?<%# Eval("U_ID") %>"

The link should be "http://home? + the value of U_ID" But the syntax isn't right I know. Whats the correct spelling?

回答1:

Try with this

 NavigateUrl='http://home/?<%# Eval("U_ID") %>'

or

 NavigateUrl='<%# "http://home/?" + (string)Eval("U_ID") %>'


回答2:

It wasn't works my site. I found the following solution:

NavigateUrl='<%# string.Format("~/Home.aspx?{0}", HttpUtility.UrlEncode(Eval("U_ID").ToString())) %>'