System.Web.UI.HtmlControls Namespace HtmlAnchor Class
Sets or retrieves the destination of the HtmlAnchor control.
Inline |
<a href = strUrl ... > |
Script |
HtmlAnchor.HRef [ = strUrl ] |
strUrl |
String specifying the URL target of the link. |
The property is read/write with no default value.
The HRef property on an HtmlAnchor control can refer to:
- any valid URI
- any valid anchor point or bookmark within a document, specified with either:
- an anchor name attribute
- or any object's id attribute.
When specifying an anchor, everything contained between the <a href ...>
and the </a>
tags defines the hyperlink to that address.
The below example illustrates using the simple yet powerful databinding feature of ASP.NET.
Databinding with the HtmlAnchor enables authors to dynamically generate hyperlinks on a Web Forms page using values from given fields in a data source.
And when databinding is used within templates in list controls such as the <asp:Repeater>, <asp:DataGrid>, and <asp:DataList>, only a single declaration is needed to generate each hyperlink item in the list. Note that the method used in this sample not only generates the link text, but also the querystring parameter of the url, which determines what argument is passed along to each link.
<a href='<%# DataBinder.Eval ( Container.DataItem, "title_id",
"details_title.aspx?titleid={0}" ) %>'>
<%# ( ( DataRowView ) Container.DataItem ) [ "title" ] %></a>
Show me
HtmlAnchor Members