Learning While Aging

How to format HyperLink NavigateUrl in designer

GridView control has several new fields to give user more control over the GridView’s format, for example, the HyperLinkField is one of them which enable user to easily format the hyper link in a GridView control. But what if you are using a server control that does not support HyperLinkField, such as DataList, Repeater? How can you format the HyperLink’s NavigateUrl in the designer that is bound to a datatable?

The answer is to use String.Format.

For example, I am using a DataList to display the employees’ information: EmployeeID, FirstName, and LastName, and EmployeeID is a HyperLink with EmployeeID as a query string appended to the NavigateUrl property. The NavigateUrl can be constructed in the designer like this:

<asp:HyperLink ID=”HyperLink1″ runat=”server” Text='<%# Bind(“EmployeedID”) %>’ NavigateUrl='<%# String.Format(“~/ViewDetails.aspx?id={0}”, Eval(“EmployeeID”))%>’></asp:HyperLink>

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
Close Bitnami banner