1

I have to admit to start that I am relatively new to ASP.NET and shamefully have not really used server tags on the client side page yet. I have a repeater on my page that iterates through the rows of a datatable and shows a hyperlink object for each item using the below tag:

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/DiseaseInfo/Syndrome.aspx?SyndromeID=<%# Eval('SYNDROME_ID')%>&SpeciesID=<%# Eval('SPECIES_ID')%>" Text='<%# Eval("SYNDROME_NAME").ToString%>'></asp:HyperLink>

The problem that I am having is that the server doesn't render out the <%# %> tags. If I put this same link into an tag then it works just fine. I am sure that it has to do with the fact that the hyperlink is already being rendered on the server-side, but I can't figure out how to change things to get it to work correctly. Any help would be greatly appreciated.

scholzr
  • 245
  • 8
  • 17
  • What issue/errors are you getting? – scartag Jan 02 '13 at 22:44
  • Sorry... I'm not actually getting an error per-se, but when the page renders, the link is rendering as http://www.mysite.com//DiseaseInfo/Syndrome.aspx?SyndromeID=<%# Eval('SYNDROME_ID')%>&SpeciesID=<%# Eval('SPECIES_ID')%>" Text='<%# Eval("SYNDROME_NAME").ToString%>. The server tags just aren't being rendered. – scholzr Jan 02 '13 at 23:04

2 Answers2

2

Reverse the order of your single / double quotes.

<asp:HyperLink runat="server" NavigateUrl='~/DiseaseInfo/Syndrome.aspx?
  SyndromeID=<%# Eval("SYNDROME_ID")%>&SpeciesID=<%# Eval("SPECIES_ID")%>'
  Text='<%# Eval("SYNDROME_NAME").ToString()%>'>
</asp:HyperLink>

This normally doesn't matter at a JavaScript / HTML level but the correct quote for C# / VB is a double quote which should be used within the Eval() method.

A slightly better approach would be to invoke a method to return this somewhat complex url:

<asp:HyperLink runat="server" NavigateUrl='<%# GetUrl() %>' />

protected string GetUrl()
{
    return string.format("Syndrome.aspx?SyndromeID={0}...", Eval("SYNDROME_ID");
}
andleer
  • 22,388
  • 8
  • 62
  • 82
  • Unfortunately, The first suggestion still didn't work. I ended up handling it in the code-behind as shown in my additional post (I couldn't figure out how to post code in the comment correctly). – scholzr Jan 03 '13 at 19:44
0

Here is how I ended up handling this:

Public Sub Repeater2_ItemDataBound(sender As Object, e As RepeaterItemEventArgs)
    If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
        Dim SpeciesID As String = CType(e.Item.DataItem, System.Data.DataRowView)("SPECIES_ID").ToString
        Dim DiseaseID As String = CType(e.Item.DataItem, System.Data.DataRowView)("DISEASE_ID").ToString
        Dim DiseaseName As String = CType(e.Item.DataItem, System.Data.DataRowView)("DISEASE_NAME").ToString
        Dim Hyperlink = CType(e.Item.FindControl("Hyperlink1"), HyperLink)

        Hyperlink.NavigateUrl = String.Format("~/DiseaseInfo/Disease.aspx?DiseaseID={0}&SpeciesID={1}", DiseaseID, SpeciesID)
        Hyperlink.Text = DiseaseName
    End If
End Sub
scholzr
  • 245
  • 8
  • 17