.NET Framework Class Library HyperLinkColumn Class A column type for the DataGrid control that contains a hyperlink for each item in the column.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)

Syntax
Public Class HyperLinkColumn _
Inherits DataGridColumn
public class HyperLinkColumn : DataGridColumn
public ref class HyperLinkColumn : public DataGridColumn
type HyperLinkColumn =
class
inherit DataGridColumn
end
The HyperLinkColumn type exposes the following members.

Constructors

Properties

Methods

Explicit Interface Implementations

Remarks
Use the HyperLinkColumn column type in a DataGrid control to create a hyperlink for each row in the DataGrid. Set the Text property to specify the caption text for the hyperlink. To specify the URL to link to when the hyperlink is clicked, set the NavigateUrl property. Note |
|---|
If you set the Text and NavigateUrl properties, all hyperlinks in the column will share the same caption and URL. |
You can also bind the text caption and URL of the hyperlinks in the HyperLinkColumn to a field in a data source instead of setting the Text and NavigateUrl properties. This allows you to display a different caption and to specify a different URL for each hyperlink in the column. Use the DataTextField property to specify a field in a data source to bind to the text caption of the hyperlinks in the column. Note |
|---|
The DataTextField and Text properties cannot both be set at the same time. If both properties are set, the DataTextField property takes precedence. |
Specify the field to bind to the URL of the hyperlink by setting the DataNavigateUrlField property. The Target property allows you to specify the window or frame to display the Web page content linked to when the hyperlink is clicked. When using data binding, you can format the text caption and URL of the hyperlink by setting the DataTextFormatString and DataNavigateUrlFormatString properties, respectively.

Examples
The following example demonstrates how to create a HyperLinkColumn that links to a separate page. Note |
|---|
The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model. |
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>HyperLinkColumn Example</title>
<script runat="server">
Function CreateDataSource() As ICollection
Dim dt As DataTable = New DataTable()
Dim dr As DataRow
Dim i As Integer
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("PriceValue", GetType(Double)))
For i = 0 to 2
dr = dt.NewRow()
dr(0) = i
dr(1) = CDbl(i) * 1.23
dt.Rows.Add(dr)
Next i
Dim dv As DataView = New DataView(dt)
Return dv
End Function
Sub Page_Load(sender As Object, e As EventArgs)
MyDataGrid.DataSource = CreateDataSource()
MyDataGrid.DataBind()
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkColumn Example</h3>
<asp:DataGrid id="MyDataGrid"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
AutoGenerateColumns="false"
runat="server">
<HeaderStyle BackColor="#aaaadd"/>
<Columns>
<asp:HyperLinkColumn
HeaderText="Select an Item"
DataNavigateUrlField="IntegerValue"
DataNavigateUrlFormatString="detailspage.aspx?id={0}"
DataTextField="PriceValue"
DataTextFormatString="{0:c}"
Target="_blank"/>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>HyperLinkColumn Example</title>
<script runat="server">
ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("PriceValue", typeof(Double)));
for (int i = 0; i < 3; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = (Double)i * 1.23;
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}
void Page_Load(Object sender, EventArgs e)
{
MyDataGrid.DataSource = CreateDataSource();
MyDataGrid.DataBind();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkColumn Example</h3>
<asp:DataGrid id="MyDataGrid"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
AutoGenerateColumns="false"
runat="server">
<HeaderStyle BackColor="#aaaadd"/>
<Columns>
<asp:HyperLinkColumn
HeaderText="Select an Item"
DataNavigateUrlField="IntegerValue"
DataNavigateUrlFormatString="detailspage.aspx?id={0}"
DataTextField="PriceValue"
DataTextFormatString="{0:c}"
Target="_blank"/>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
The following corresponding example displays the item selected in the previous example.
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Details page for DataGrid</title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Label1.Text = "You selected item: " & Request.QueryString("id")
End Sub
</script>
</head>
<body>
<h3>Details page for DataGrid</h3>
<asp:Label id="Label1"
runat="server"/>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Details page for DataGrid</title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
Label1.Text = "You selected item: " + Request.QueryString["id"];
}
</script>
</head>
<body>
<h3>Details page for DataGrid</h3>
<asp:Label id="Label1"
runat="server"/>
</body>
</html>

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
Bibliothèque de classes .NET Framework HyperLinkColumn, classe Type de colonne du contrôle DataGrid contenant un lien hypertexte pour chaque élément de la colonne.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
Public Class HyperLinkColumn _
Inherits DataGridColumn
public class HyperLinkColumn : DataGridColumn
public ref class HyperLinkColumn : public DataGridColumn
type HyperLinkColumn =
class
inherit DataGridColumn
end
Le type HyperLinkColumn expose les membres suivants.

Constructeurs

Méthodes

Implémentations d'interface explicite

Notes
Utilisez le type de colonne HyperLinkColumn dans un contrôle DataGrid pour créer un lien hypertexte par ligne de DataGrid. Définissez la propriété Text de manière à ce qu'elle spécifie le texte de légende du lien. Pour spécifier l'URL à laquelle le lien hypertexte se dirige lorsqu'il est sélectionné par un clic, définissez la propriété NavigateUrl. Remarque |
|---|
Si vous définissez les propriétés Text et NavigateUrl, tous les liens hypertexte de la colonne partagent la même légende et la même URL. |
Il est également possible d'associer la légende le texte et l'URL des liens hypertexte de HyperLinkColumn à un champ situé dans une source de données au lieu de définir les propriétés Text et NavigateUrl. Ceci permet d'afficher une légende différente et de spécifier une URL différente par lien hypertexte de la colonne. Utilisez la propriété DataTextField pour spécifier le champ d'une source de données à lier à la légende de texte des liens hypertexte de la colonne. Remarque |
|---|
Les propriétés DataTextField et Text ne peuvent pas être définies toutes les deux en même temps. Si les deux propriétés sont définies, la propriété DataTextField est prioritaire. |
Pour spécifier le champ à lier à l'URL du lien hypertexte, définissez la propriété DataNavigateUrlField. La propriété Target permet de spécifier la fenêtre ou le frame dans lequel afficher le contenu de page Web associé au lien hypertexte sélectionné par un clic. Lorsque vous utilisez une liaison de données, vous pouvez définir respectivement les propriétés DataTextFormatString et DataNavigateUrlFormatString pour mettre en forme la légende de texte et l'URL du lien hypertexte.

Exemples
L'exemple suivant montre comment créer HyperLinkColumn établissant un lien vers une page séparée. Remarque |
|---|
L'exemple de code suivant utilise un modèle de code de fichier unique ; il est possible qu'il ne fonctionne pas correctement s'il est directement copié dans un fichier code-behind. Cet exemple de code doit être copié dans un fichier texte vide doté d'une extension .aspx. Pour plus d'informations sur le modèle de code des Web Forms, consultez Modèle de code des pages Web ASP.NET. |
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>HyperLinkColumn Example</title>
<script runat="server">
Function CreateDataSource() As ICollection
Dim dt As DataTable = New DataTable()
Dim dr As DataRow
Dim i As Integer
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("PriceValue", GetType(Double)))
For i = 0 to 2
dr = dt.NewRow()
dr(0) = i
dr(1) = CDbl(i) * 1.23
dt.Rows.Add(dr)
Next i
Dim dv As DataView = New DataView(dt)
Return dv
End Function
Sub Page_Load(sender As Object, e As EventArgs)
MyDataGrid.DataSource = CreateDataSource()
MyDataGrid.DataBind()
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkColumn Example</h3>
<asp:DataGrid id="MyDataGrid"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
AutoGenerateColumns="false"
runat="server">
<HeaderStyle BackColor="#aaaadd"/>
<Columns>
<asp:HyperLinkColumn
HeaderText="Select an Item"
DataNavigateUrlField="IntegerValue"
DataNavigateUrlFormatString="detailspage.aspx?id={0}"
DataTextField="PriceValue"
DataTextFormatString="{0:c}"
Target="_blank"/>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>HyperLinkColumn Example</title>
<script runat="server">
ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("PriceValue", typeof(Double)));
for (int i = 0; i < 3; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = (Double)i * 1.23;
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}
void Page_Load(Object sender, EventArgs e)
{
MyDataGrid.DataSource = CreateDataSource();
MyDataGrid.DataBind();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkColumn Example</h3>
<asp:DataGrid id="MyDataGrid"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
AutoGenerateColumns="false"
runat="server">
<HeaderStyle BackColor="#aaaadd"/>
<Columns>
<asp:HyperLinkColumn
HeaderText="Select an Item"
DataNavigateUrlField="IntegerValue"
DataNavigateUrlFormatString="detailspage.aspx?id={0}"
DataTextField="PriceValue"
DataTextFormatString="{0:c}"
Target="_blank"/>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
L'exemple suivant affiche l'élément sélectionné dans l'exemple précédent.
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Details page for DataGrid</title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Label1.Text = "You selected item: " & Request.QueryString("id")
End Sub
</script>
</head>
<body>
<h3>Details page for DataGrid</h3>
<asp:Label id="Label1"
runat="server"/>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Details page for DataGrid</title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
Label1.Text = "You selected item: " + Request.QueryString["id"];
}
</script>
</head>
<body>
<h3>Details page for DataGrid</h3>
<asp:Label id="Label1"
runat="server"/>
</body>
</html>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0, 1.1, 1.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
RéférenceAutres ressources
|