24

First I was changing HyperLink.NavigateUrl in code-behind on Page_Load().

But after I decided to do it in design using Eval() method.

<asp:HyperLink runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Eval("type"), Eval("id")) %>' Text="Refuse" />

or

<asp:HyperLink ID="urlRefuse" runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />

where id and type - are variables from Request.

But it doesn't work. Only raw text 'Refuse' is shown. Where is my mistake? Thanks in advance.

abatishchev
  • 98,240
  • 88
  • 296
  • 433

6 Answers6

63

this is working great

NavigateUrl='<%# Eval("type","~/Refuse.aspx?type={0}") %>'
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Hamdy Mohamed
  • 646
  • 6
  • 2
  • I stopped using web forms years ago, and yet I come years later to learn something like this was so easy. – Ernesto Sep 28 '16 at 21:18
17

This worked for me

NavigateUrl='<%# String.Format("{0}.aspx?ID={1}", DataBinder.Eval(Container.DataItem, "Category"), DataBinder.Eval(Container.DataItem, "Post_ID")) %>'
Etienne
  • 7,141
  • 42
  • 108
  • 160
4

Try and ViewSource in your browser, what's being rendered to the client in your href? Is it what you expected?. If you are trying to use variables from the request collection you can't use Eval, you need to use the Request query string parameters.

<asp:HyperLink runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />
Phaedrus
  • 8,351
  • 26
  • 28
-1

Try this one:

<asp:HyperLink ID="HyperLink2" runat="server" onclick='<%# String.Format("AcceptUser({0},{1})",Eval("UserId"), Eval("TsId")) %>' NavigateUrl="javascript:void(0)" Visible='<%# (bool)Eval("CanDelete") %>'>Accept</asp:HyperLink>  
abatishchev
  • 98,240
  • 88
  • 296
  • 433
ACP
  • 34,682
  • 100
  • 231
  • 371
-1

Try this:

HttpUtility.UrlEncode(Eval("type")
abatishchev
  • 98,240
  • 88
  • 296
  • 433
ACP
  • 34,682
  • 100
  • 231
  • 371
-1

Try this it worked for me:

Eval("type").ToString()
abatishchev
  • 98,240
  • 88
  • 296
  • 433
ACP
  • 34,682
  • 100
  • 231
  • 371