Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hyperlinks in repeater controls

Status
Not open for further replies.

xavstone

Technical User
Apr 12, 2005
33
GB
Hi, im trying to turn some text in a repeater into a hyperlink that sends a primary key to another page in the url.

in php i would just break into the html and pop the field in like:

<a href="article_view.php?=<? echo($articleID); ?>">Link name</a>.... etc etc

Well heres the repeater. The bit in bold is bit i would like to become a link. The variable i want to pass on is called articleID. thanks in advance for any suggestions, ben


<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate>
<table><tr><td>
<font class="majorHeader">ABC list of articles in library</font></td></tr>
</HeaderTemplate>
<ItemTemplate>
<tr><td><font class="repeaterHeader"><asp:HyperLink runat="server"><%# DataBinder.Eval(Container.DataItem, "heading") %></asp:HyperLink></font><br /></td><td></td></tr>
<tr><td><font class="repeaterAuthor"><%# DataBinder.Eval(Container.DataItem, "author") %>, <%# DataBinder.Eval(Container.DataItem, "datewritten") %></font><br /></td></tr>
<tr><td><font class="repeaterDescription"><%# DataBinder.Eval(Container.DataItem, "description") %></font><br /></td></tr>
</ItemTemplate>
<SeparatorTemplate><tr><td><hr /></td></tr></SeparatorTemplate>
<FooterTemplate>
<tr><td><br /><hr /><br /></td></tr></table>
</FooterTemplate>
</asp:Repeater>[/b]
</asp:Content>
 
Hi,

You can just use a href in this case:-

<a href="YourPage.aspx?articleID=<%# DataBinder.Eval(Container.DataItem, "articleID") %>"><%# DataBinder.Eval(Container.DataItem, "Heading") %></a>

HTH
j

 
omg... i spent hours on that :eek:

am i breaking some kind of best practice code by not using the <asp:hyperlink....?

thanks, j
 
You can use the HTML anchor tag if you wish. If you want to be able to access it server-side though, you'll have to stick with the HyperLink control (or add runat="server" to your anchor tag). To use the Hyperlink control, you can just set it's NavigateURL property e.g.
Code:
 <asp:HyperLink id="hyperlink1" 
                  NavigateUrl=<%# DataBinder.Eval(Container.DataItem, "heading") %> 
                  Text="Test" 
                  runat="server"/>
Also, while you're at it, you might want to have a read up on HTML and CSS as there's some pretty awful and outdated HTML in the example you posted.



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ok im getting the syntax thanks. re: html and css i know i suck at it, i have a guy that redoes that for me when i get the processes down and i suppose i have never really considered high on my agenda, its on the list after c#, asp, javascript, java, ajax, and sql! if im still sane at that point.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top