0

Let's say I have a repeater with the code:

<ItemTemplate>
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#DataBinder.Eval(Container.DataItem, "FileLeafRef")%>'>
        <h2><%# DataBinder.Eval(Container.DataItem, "Title")%></h2>     
    </asp:HyperLink>                
</ItemTemplate>

The FileLeadRef variable only contains the page name though (like test.aspx and not the full URL which I need). I can get the first part of the URL in a variable in page_load so I need to do something like:

NavigateUrl='<%myVariable + "/"%><%#DataBinder.Eval(Container.DataItem, "FileLeafRef")%>' but it obviously doesn't work and a have tried a few varieties without success.

Any suggestions?

Thanks in advance.

2 Answers 2

1

You can write

<%# myVariable + "/" + DataBinder.Eval(Container.DataItem, "FileLeafRef")%>
Sign up to request clarification or add additional context in comments.

2 Comments

With that I get the name 'siteUrl' does not exist in the current context so I must be missing something.
@user: Make it a field in the class.
0

I usually move url construction in a code-behind function:

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# UrlHelper(myVariable ,DataBinder.Eval(Container.DataItem, "FileLeafRef"))%>'>

protected string UrlHelper(string prefix, object leaf)
{
   return prefix + "/" + leaf.ToString();

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.