Reputation: 5480
I'd like to make anchors to every post in my asp.net forum. Every forum's post is rendered using repeater control. How can I render <a name="anchor_name"></a>
in asp.net?
Upvotes: 0
Views: 4305
Reputation: 5480
Ok. I've resolved it this way:
<a name='<%# DataBinder.Eval(Container.DataItem, "Id") %>' />
where Id is the property of binded entity.
Upvotes: 0
Reputation: 23766
Extend the System.Web.UI.WebControls.HyperLink class, and override UniqueID property to return the actual ID:
override string UniqueID { get { return ID; } }
Use this new user control in the item template of the repeater.
<MyPrefix:MyHyperLink ID="IDOfYourHyperLink" ... />
On ItemDataBound do:
(e.Item.FindControl("IDOfYourHyperLink") as MyHyperlink).ID = NowIKnowWhatToUseHere;
Upvotes: 0
Reputation: 3687
This won't be exact code as I'm not in VS to ensure the syntax but something like this should get you were you want to go.
<a name="<%# Bind('PostId') %>" runat="server" />
Upvotes: 1
Reputation: 955
Adding <a name="anchor_name"></a>
in the ItemTempate of the repeater at the appropriate spot should do the trick. A little more information might help.
Upvotes: -1
Reputation: 4020
<a name='<%# Eval("PostId") %>' />
where PostId is the name of the property you want to appear in your anchor.
Upvotes: 6