How to use HyperLink hyperlink control in ASP. NET

  • 2021-07-21 08:14:55
  • OfStack

HyperLink (Hyperlink)

Role: Responsible for navigation between pages

属性 作用
NavigateUrl url 将要跳转的页面地址(url)
Font-Underline False 去除超链接下划线

1. Basic usage of the HyperLink control

The most used one is nothing more than NavigateUrl. Since it is a hyperlink, there must be a link address. See the specific usage below:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HyperLink.aspx.cs" Inherits="WebControls_HyperLink" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:HyperLink ID="hlkMenu" runat="server" Font-Strikeout="False"
            Font-Underline="False" NavigateUrl="~/WebControls/CheckBoxList.aspx"> Check Box Group Page </asp:HyperLink>
    </div>
    </form>
</body>
</html>

2. HyperLink NavigateUrl Hyperlink Data Binding Method

HyperLink controls often appear in Repeater controls, and link addresses often have background data binding, which can be implemented in two ways, as follows:


<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "~/SysManage/RoleManage/DistributeRole.aspx?roleId="+DataBinder.Eval(Container.DataItem,"RoleId")%>'> Assign permissions </asp:HyperLink>


<asp:HyperLink ID="HyperLink1" runat="server" ImageUrl="images/hammer_screwdriver.png" NavigateUrl='<%# Eval("UserId", "UserInfoDetails.aspx?UserId={0}") %>'> User details </asp:HyperLink>


Related articles: