asp:hyperlink object in Repeater control ??

M

Martin Dew

Having some problems getting a hyperlink object to work in my repeater
control, It displays the text I have asked it to for the hyperlink, but it
does not act as a link. My repeater code is below but here is the snippet of
my asp:hyperlink object;

<asp:HyperLink
NavigateUrl="authonly/clientdetails.aspx?searchID="+<%#DataBinder.Eval(Conta
iner.DataItem,"CLIENTREF")%>
ID="Hyperlink1"><%#DataBinder.Eval(Container.DataItem,
"NAME")%></asp:HyperLink>

If anyone can help I would be much appreciative. The field clientref by the
way is stored as a guid in ms sql datastore.

<asp:repeater id="statsRepeater" runat="server">
<HeaderTemplate>
<table border="0" width="100%" cellspacing="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td colspan="2" class="tableLightBlue">
<asp:HyperLink
NavigateUrl="authonly/clientdetails.aspx?searchID="+<%#DataBinder.Eval(Conta
iner.DataItem,"CLIENTREF")%>
ID="Hyperlink1"><%#DataBinder.Eval(Container.DataItem,
"NAME")%></asp:HyperLink>
</td>
</tr>
<tr>
<td width="60%" class="tableFailureBodyWhite">Last Successful Inbound</td>
<td width="40%"
class="tableFailureBodyWhite"><%#DataBinder.Eval(Container.DataItem,
"LASTSUCCESSFULINBOUND")%></td>
</tr>
<tr>
<td width="60%" class="tableFailureBodyWhite">Last IP Connection
Attempt</td>
<td width="40%"
class="tableFailureBodyWhite"><%#DataBinder.Eval(Container.DataItem,
"LASTIPCONNECTATTEMPT")%></td>
</tr>
<tr>
<td width="60%" class="tableFailureBodyWhite">Last IP Successful
Disconnection</td>
<td width="40%"
class="tableFailureBodyWhite"><%#DataBinder.Eval(Container.DataItem,
"LASTIPSUCCESSFULDISCONNECT")%></td>
</tr>
<tr>
<td width="60%" class="tableFailureBodyWhite">First IP Failure</td>
<td width="40%"
class="tableFailureBodyWhite"><%#DataBinder.Eval(Container.DataItem,
"FIRSTIPFAILURE")%></td>
</tr>
<tr>
<td width="60%" class="tableFailureBodyWhite">Next IP Retry</td>
<td width="40%"
class="tableFailureBodyWhite"><%#DataBinder.Eval(Container.DataItem,
"NEXTIPRETRY")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
</td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>
 
K

Ken Cox [Microsoft MVP]

Hi Martin,

You for to use runat="server" so it wasn't executing on the server. I also
found a couple of syntax errors. My version is below.

Does this help?

Ken
Microsoft MVP [ASP.NET]

<asp:repeater id="statsRepeater" runat="server">
<HeaderTemplate>
<table border="0" width="100%" cellspacing="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td colspan="2" class="tableLightBlue">
<asp:HyperLink Runat=server
NavigateUrl='authonly/clientdetails.aspx?searchID=<%#DataBinder.Eval(Container.DataItem,"CLIENTREF")%>'
ID="Hyperlink1">
<%#DataBinder.Eval(Container.DataItem,"NAME")%>
</asp:HyperLink>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
</td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>
 
K

Ken Cox [Microsoft MVP]

Hi Martin,

You forgot to use runat="server" so it wasn't executing on the server. I
also
found a couple of syntax errors. My version is below.

Does this help?

Ken
Microsoft MVP [ASP.NET]

<asp:repeater id="statsRepeater" runat="server">
<HeaderTemplate>
<table border="0" width="100%" cellspacing="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td colspan="2" class="tableLightBlue">
<asp:HyperLink Runat=server
NavigateUrl='authonly/clientdetails.aspx?searchID=<%#DataBinder.Eval(Container.DataItem,"CLIENTREF")%>'
ID="Hyperlink1">
<%#DataBinder.Eval(Container.DataItem,"NAME")%>
</asp:HyperLink>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
</td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>
 
M

Martin Dew

thanks Ken. However it does make this hyperlink actually act as a hyperlink,
it does not take the databound value and add it to the Navigate URL string.

when you hover over the link it simply tries to navigate to
//authonly/clientdetails.aspx?searchID=<%#DataBinder.Eval(Container.DataItem
,"CLIENTREF")%>

instead of replacing the
<%#DataBinder.Eval(Container.DataItem,"CLIENTREF")%> with the value of its
databoudn field.

any advice ?
 
K

Ken Cox [Microsoft MVP]

Hi Martin,

Oops. Sorry about that. Not sure what's going on but there's another way to
skin this cat... use a helper function:

Function MakeURL(ByVal strURL As String) As String
Return "clientdetails.aspx?searchID=" & strURL
End Function

<asp:HyperLink Runat=server NavigateUrl='<%#
MakeURL(DataBinder.Eval(Container.DataItem,"CLIENTREF"))%>' ID="Hyperlink1">

My test code is below.

Does *this* help? <grin>

Ken
Toronto


<asp:repeater id="statsRepeater" runat="server">
<HeaderTemplate>
<table border="0" width="100%" cellspacing="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td colspan="2" class="tableLightBlue">
<asp:HyperLink Runat=server NavigateUrl='<%#
MakeURL(DataBinder.Eval(Container.DataItem,"CLIENTREF"))%>' ID="Hyperlink1">
<%#DataBinder.Eval(Container.DataItem,"NAME")%>
</asp:HyperLink>
<asp:HyperLink id="Hyperlink2" runat="server" NavigateUrl="asas.aspx"
ImageUrl="dfdf.aspx">HyperLink</asp:HyperLink></P>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
</td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
statsRepeater.DataSource = _
CreateDataSource()
statsRepeater.DataBind()
End Sub

Function MakeURL(ByVal strURL As String) As String
Return "clientdetails.aspx?searchID=" & strURL
End Function

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Name", GetType(String)))
dt.Columns.Add(New DataColumn _
("CLIENTREF", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = "ABCD-EFGH" & i.ToString
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
 
M

Martin Dew

Ken, thanks for your help on this.

I am writing this in c#, so I have added to my code page

public string MakeURL(string strGuid)
{
return string.Format("authonly/clientdetails.aspx?searchID={0}",strGuid);
}

and in my html view I now have this ;

<asp:HyperLink Runat=server
NavigateUrl='<%#MakeURL(DataBinder.Eval(Container.DataItem,"CLIENTREF"))%>'
ID="Hyperlink2">
<%#DataBinder.Eval(Container.DataItem,"NAME")%>
</asp:HyperLink>

but when the page tries to load I get the following compilation error ;

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for
'Concentrator.index.MakeURL(string)' has some invalid arguments

Source Error:

Line 87: <tr>
Line 88: <td colspan="2" class="tableLightBlue">
Line 89: <asp:HyperLink Runat=server
Line 90:
NavigateUrl='<%#MakeURL(DataBinder.Eval(Container.DataItem,"NAME"))%>'
Line 91: ID="Hyperlink2">


Source File: http://localhost/Concentrator/index.aspx Line: 89

I expect I am doing something really stupid..

Regards

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top