HyperLink with NavigateUrl with Eval(). Where is the mistake?

76,820

Solution 1

this is working great

NavigateUrl='<%# Eval("type","~/Refuse.aspx?type={0}") %>'

Solution 2

This worked for me

NavigateUrl='<%# String.Format("{0}.aspx?ID={1}", DataBinder.Eval(Container.DataItem, "Category"), DataBinder.Eval(Container.DataItem, "Post_ID")) %>'

Solution 3

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" />
Share:
76,820
abatishchev
Author by

abatishchev

This is my GUID. There are many like it but this one is mine. My GUID is my best friend. It is my life. I must master it as I must master my life. Without me, my GUID is useless. Without my GUID I am useless.

Updated on July 09, 2022

Comments

  • abatishchev
    abatishchev almost 2 years

    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.