Search code examples
asp.netgridviewanchorinternal-link

How can anchor tags (for internal links) be put into a gridview?


I have a long alphabetical list to be displayed by a gridview.

I need to have links at the top of the page that will link to anchors in the gridview. How can I get anchor tags in the gridview so that the links will jump to them when clicked?

Note: Paging is not an option

Thanks!


Solution

  • Set the GridView's ClientIDMode to Static or Predictable(if using Framework 4.0) to avoid ASP.Net generating unique names according to their NamingContainers(GridViewRow). You should ensure that the ID's are unique by yourself from RowDataBound(f.e. append an identifier).

    If you are using Framework < 4.0 you have to generate the HyperLink's NavigateUrl from RowDataBound of the GridView via the ClientID of your link targets.