2

I've got a:

  • Data repeater
  • Control in the repeater

And I'd like to put some values into the controls. At the moment I have a control in it as:

<asp:Repeater runat="server" ID="ArchiveEntryRepeater">
    snip
    <asp:HyperLink ID="HyperLink1" ToolTip="Comment on Some Entry Title Here" runat="server" NavigateUrl="~/Blog/7/How-to-know-when-this/Comments">
        <strong><%# DataBinder.Eval(Container.DataItem, "Comments")%></strong> Comments
    </asp:HyperLink>
    snip
</asp:Repeater> 

Which works fine, but I want to put

<%# DataBinder.Eval(Container.DataItem, "Title")%>

Into the NavigateURL property of the Hyperlink. Just putting it in doesn't seem to work!

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456

3 Answers3

3

Try enclosing your NavigateURL in apostrophes instead of double quotes to not confuse the ASP.NET parser:

<asp:HyperLink runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "Title")%>' [...]>[...]</asp:HyperLink>

This might be your issue.

David Pratte
  • 1,036
  • 8
  • 14
  • Duh, I couldn't test it because I'm at work, what happens if you try with NavigateUrl (instead of URL)? It used to work for me (except when there was text before the `<%#`). – David Pratte Apr 14 '11 at 19:19
1

You can always bind on the back end using the event itemdatabound. It has some advantages especially where the data is not a neat view or needs some type of major manipulation.

rerun
  • 25,014
  • 6
  • 48
  • 78
0

Another option would be to loose the control and replace it with an html anchor control like this:

 <asp:Repeater>
        <ItemTemplate>
            <a id="HyperLink1" title="Comment on Some Entry Title Here" href='<%# DataBinder.Eval(Container.DataItem, "Title")%>'
                style="font-weight: bold">'<%# DataBinder.Eval(Container.DataItem, "Comments")%>'</a>
        </ItemTemplate>
    </asp:Repeater>

Once the server renders a hyperlink to the client there is generally no reason to have it "runat='server'" . The purpose is to navigate to another page so the overhead of using an asp:HyperLink vs. an nchor is wasted.

Cos Callis
  • 5,051
  • 3
  • 30
  • 57