Question

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?

Was it helpful?

Solution

<a name='<%# Eval("PostId") %>' />

where PostId is the name of the property you want to appear in your anchor.

OTHER TIPS

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" />

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;

Ok. I've resolved it this way:

<a name='<%# DataBinder.Eval(Container.DataItem, "Id") %>' />

where Id is the property of binded entity.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top