Suggérer une traduction
 
Suggestions d'autres utilisateurs :

progress indicator
Aucune autre suggestion.
Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 4
Espaces de noms System.Web
System.Web.UI.WebControls
HyperLinkColumn, classe
Réduire tout/Développer tout Réduire tout
Affichage du contenu :  côte à côteAffichage du contenu : côte à côte
.NET Framework Class Library
HyperLinkColumn Class

A column type for the DataGrid control that contains a hyperlink for each item in the column.

System..::.Object
  System.Web.UI.WebControls..::.DataGridColumn
    System.Web.UI.WebControls..::.HyperLinkColumn

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic
Public Class HyperLinkColumn _
    Inherits DataGridColumn
C#
public class HyperLinkColumn : DataGridColumn
Visual C++
public ref class HyperLinkColumn : public DataGridColumn
F#
type HyperLinkColumn =  
    class
        inherit DataGridColumn
    end

The HyperLinkColumn type exposes the following members.

  NameDescription
Public methodHyperLinkColumnInitializes a new instance of the HyperLinkColumn class.
Top
  NameDescription
Public propertyDataNavigateUrlFieldGets or sets the field from a data source to bind to the URL of the hyperlinks in the HyperLinkColumn.
Public propertyDataNavigateUrlFormatStringGets or sets the display format for the URL of the hyperlinks in the HyperLinkColumn when the URL is data-bound to a field in a data source.
Public propertyDataTextFieldGets or sets the field from a data source to bind to the text caption of the hyperlinks in the HyperLinkColumn.
Public propertyDataTextFormatStringGets or sets the display format for the text caption of the hyperlinks in the HyperLinkColumn column.
Protected propertyDesignModeGets a value that indicates whether the column is in design mode. (Inherited from DataGridColumn.)
Public propertyFooterStyleGets the style properties for the footer section of the column. (Inherited from DataGridColumn.)
Public propertyFooterTextGets or sets the text displayed in the footer section of the column. (Inherited from DataGridColumn.)
Public propertyHeaderImageUrlGets or sets the location of an image to display in the header section of the column. (Inherited from DataGridColumn.)
Public propertyHeaderStyleGets the style properties for the header section of the column. (Inherited from DataGridColumn.)
Public propertyHeaderTextGets or sets the text displayed in the header section of the column. (Inherited from DataGridColumn.)
Protected propertyIsTrackingViewStateGets a value that determines whether the DataGridColumn object is marked to save its state. (Inherited from DataGridColumn.)
Public propertyItemStyleGets the style properties for the item cells of the column. (Inherited from DataGridColumn.)
Public propertyNavigateUrlGets or sets the URL to link to when a hyperlink in the column is clicked.
Protected propertyOwnerGets the DataGrid control that the column is a member of. (Inherited from DataGridColumn.)
Public propertySortExpressionGets or sets the name of the field or expression to pass to the OnSortCommand method when a column is selected for sorting. (Inherited from DataGridColumn.)
Public propertyTargetGets or sets the target window or frame to display the Web page content that is linked to when the hyperlink in the column is clicked.
Public propertyTextGets or sets the text caption to display for the hyperlinks in the column.
Protected propertyViewStateGets the System.Web.UI..::.StateBag object that allows a column derived from the DataGridColumn class to store its properties. (Inherited from DataGridColumn.)
Public propertyVisibleGets or sets a value that indicates whether the column is visible in the DataGrid control. (Inherited from DataGridColumn.)
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected methodFormatDataNavigateUrlValueFormats a data-bound URL using the format specified by the DataNavigateUrlFormatString property.
Protected methodFormatDataTextValueFormats a data-bound text caption using the format specified by the DataTextFormatString property.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeProvides the base implementation to reset a column derived from the DataGridColumn class to its initial state. (Overrides DataGridColumn..::.Initialize()()().)
Public methodInitializeCellInitializes the cell representing this column with the contained hyperlink. (Overrides DataGridColumn..::.InitializeCell(TableCell, Int32, ListItemType).)
Protected methodLoadViewStateLoads the state of the DataGridColumn object. (Inherited from DataGridColumn.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnColumnChangedCalls the DataGridDesigner..::.OnColumnsChanged method. (Inherited from DataGridColumn.)
Protected methodSaveViewStateSaves the current state of the DataGridColumn object. (Inherited from DataGridColumn.)
Public methodToStringReturns the string representation of the column. (Inherited from DataGridColumn.)
Protected methodTrackViewStateCauses tracking of view-state changes to the server control so they can be stored in the server control's System.Web.UI..::.StateBag object. (Inherited from DataGridColumn.)
Top
  NameDescription
Explicit interface implemetationPrivate propertyIStateManager..::.IsTrackingViewStateInfrastructure. Gets a value that indicates whether the column is tracking view state changes. (Inherited from DataGridColumn.)
Explicit interface implemetationPrivate methodIStateManager..::.LoadViewStateInfrastructure. Loads previously saved state. (Inherited from DataGridColumn.)
Explicit interface implemetationPrivate methodIStateManager..::.SaveViewStateInfrastructure. Returns an object containing state changes. (Inherited from DataGridColumn.)
Explicit interface implemetationPrivate methodIStateManager..::.TrackViewStateInfrastructure. Starts tracking state changes. (Inherited from DataGridColumn.)
Top

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.

NoteNote

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.

NoteNote

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.

NoteNote

The DataNavigateUrlField and NavigateUrl properties cannot both be set at the same time. If both properties are set, the DataNavigateUrlField property takes precedence.

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.

Caution noteCaution

This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input. For more information, see Securing Standard ControlsHow to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Validating User Input in ASP.NET Web Pages.

The following example demonstrates how to create a HyperLinkColumn that links to a separate page.

NoteNote

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.

Visual Basic
<%@ 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>
C#
<%@ 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.

Visual Basic
<%@ 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>

C#
<%@ 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>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

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.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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.

System..::.Object
  System.Web.UI.WebControls..::.DataGridColumn
    System.Web.UI.WebControls..::.HyperLinkColumn

Espace de noms :  System.Web.UI.WebControls
Assembly :  System.Web (dans System.Web.dll)
Visual Basic
Public Class HyperLinkColumn _
    Inherits DataGridColumn
C#
public class HyperLinkColumn : DataGridColumn
VisualC++
public ref class HyperLinkColumn : public DataGridColumn
F#
type HyperLinkColumn =  
    class
        inherit DataGridColumn
    end

Le type HyperLinkColumn expose les membres suivants.

  NomDescription
Méthode publiqueHyperLinkColumnInitialise une nouvelle instance de la classe HyperLinkColumn.
Début
  NomDescription
Propriété publiqueDataNavigateUrlFieldObtient ou définit le champ issu de la source de données à lier à l'URL des liens hypertexte dans HyperLinkColumn.
Propriété publiqueDataNavigateUrlFormatStringObtient ou définit le format d'affichage de l'URL des liens hypertexte dans HyperLinkColumn lorsque l'URL est liée aux données d'un champ situé dans une source de données.
Propriété publiqueDataTextFieldObtient ou définit le champ issu de la source de données à lier à la légende de texte des liens hypertexte dans HyperLinkColumn.
Propriété publiqueDataTextFormatStringObtient ou définit le format d'affichage de la légende de texte des liens hypertexte dans la colonne HyperLinkColumn.
Propriété protégéeDesignModeObtient une valeur indiquant si la colonne est en mode design. (Hérité de DataGridColumn.)
Propriété publiqueFooterStyleObtient les propriétés de style pour la section de pied de page de la colonne. (Hérité de DataGridColumn.)
Propriété publiqueFooterTextObtient ou définit le texte affiché dans la section de pied de page de la colonne. (Hérité de DataGridColumn.)
Propriété publiqueHeaderImageUrlObtient ou définit l'emplacement d'une image à afficher dans la section d'en-tête de la colonne. (Hérité de DataGridColumn.)
Propriété publiqueHeaderStyleObtient les propriétés de style pour la section d'en-tête de la colonne. (Hérité de DataGridColumn.)
Propriété publiqueHeaderTextObtient ou définit le texte affiché dans la section d'en-tête de la colonne. (Hérité de DataGridColumn.)
Propriété protégéeIsTrackingViewStateObtient une valeur qui détermine si l'objet DataGridColumn est marqué pour enregistrer son état. (Hérité de DataGridColumn.)
Propriété publiqueItemStyleObtient les propriétés de style pour les cellules d'éléments de la colonne. (Hérité de DataGridColumn.)
Propriété publiqueNavigateUrlObtient ou définit l'URL vers laquelle établir un lien quand un lien hypertexte a été sélectionné par un clic dans la colonne.
Propriété protégéeOwnerObtient le contrôle DataGrid dont la colonne est membre. (Hérité de DataGridColumn.)
Propriété publiqueSortExpressionObtient ou définit le nom du champ ou de l'expression à passer à la méthode OnSortCommand lorsqu'une colonne est sélectionnée pour être triée. (Hérité de DataGridColumn.)
Propriété publiqueTargetObtient ou définit la fenêtre ou le frame cible pour afficher le contenu de la page Web vers laquelle pointe le lien hypertexte sélectionné par un clic dans la colonne.
Propriété publiqueTextObtient ou définit la légende de texte accompagnant les liens hypertexte de la colonne.
Propriété protégéeViewStateObtient l'objet System.Web.UI..::.StateBag qui permet à une colonne dérivée de la classe DataGridColumn de stocker ses propriétés. (Hérité de DataGridColumn.)
Propriété publiqueVisibleObtient ou définit une valeur qui indique si la colonne est visible dans le contrôle DataGrid. (Hérité de DataGridColumn.)
Début
  NomDescription
Méthode publiqueEquals(Object)Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.)
Méthode protégéeFinalizeAutorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.)
Méthode protégéeFormatDataNavigateUrlValueMet en forme une URL liée aux données, à l'aide du format spécifié par la propriété DataNavigateUrlFormatString.
Méthode protégéeFormatDataTextValueMet en forme une légende de texte liée aux données, à l'aide du format spécifié par la propriété DataTextFormatString.
Méthode publiqueGetHashCodeSert de fonction de hachage pour un type particulier. (Hérité de Object.)
Méthode publiqueGetTypeObtient le Type de l'instance actuelle. (Hérité de Object.)
Méthode publiqueInitializeFournit l'implémentation de base permettant de rétablir l'état initial d'une colonne dérivée de la classe DataGridColumn. (Substitue DataGridColumn..::.Initialize()()().)
Méthode publiqueInitializeCellInitialise la cellule représentant cette colonne avec le lien hypertexte contenu. (Substitue DataGridColumn..::.InitializeCell(TableCell, Int32, ListItemType).)
Méthode protégéeLoadViewStateCharge l'état de l'objet DataGridColumn. (Hérité de DataGridColumn.)
Méthode protégéeMemberwiseCloneCrée une copie superficielle de l'objet Object actif. (Hérité de Object.)
Méthode protégéeOnColumnChangedAppelle la méthode DataGridDesigner..::.OnColumnsChanged. (Hérité de DataGridColumn.)
Méthode protégéeSaveViewStateEnregistre l'état actuel de l'objet DataGridColumn. (Hérité de DataGridColumn.)
Méthode publiqueToStringRetourne la représentation sous forme de chaîne de la colonne. (Hérité de DataGridColumn.)
Méthode protégéeTrackViewStateProvoque le suivi des modifications de l'état d'affichage pour le contrôle serveur afin qu'elles puissent être stockées dans l'objet System.Web.UI..::.StateBag du contrôle serveur. (Hérité de DataGridColumn.)
Début
  NomDescription
Implémentation d'interface explicitePropriété privéeIStateManager..::.IsTrackingViewStateInfrastructure. Obtient une valeur qui indique si la colonne suit les changements de l'état d'affichage. (Hérité de DataGridColumn.)
Implémentation d'interface expliciteMéthode privéeIStateManager..::.LoadViewStateInfrastructure. Charge l'état enregistré précédemment. (Hérité de DataGridColumn.)
Implémentation d'interface expliciteMéthode privéeIStateManager..::.SaveViewStateInfrastructure. Retourne un objet contenant les modifications de l'état. (Hérité de DataGridColumn.)
Implémentation d'interface expliciteMéthode privéeIStateManager..::.TrackViewStateInfrastructure. Commence à suivre les modifications d'état. (Hérité de DataGridColumn.)
Début

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.

RemarqueRemarque

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.

RemarqueRemarque

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.

RemarqueRemarque

Les propriétés DataNavigateUrlField et NavigateUrl 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é DataNavigateUrlField est prioritaire.

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.

Remarque AttentionAttention

Ce contrôle peut être utilisé pour afficher des entrées d'utilisateur qui peuvent inclure un script client nuisible. Vérifiez toutes les informations envoyées par un client pour un script exécutable, des instructions SQL ou un autre code avant de les afficher dans votre application. Vous pouvez utiliser des contrôles de validation pour vérifier les entrées d'utilisateur avant d'afficher le texte d'entrée dans un contrôle. ASP.NET fournit une fonctionnalité de validation de la demande d'entrée pour bloquer les scripts et le code HTML dans les entrées d'utilisateur. Pour plus d'informations, consultez Sécurisation de contrôles standard, Comment : se protéger contre les attaques de script dans une application Web en utilisant l'encodage HTML et Validation des entrées d'utilisateur dans des pages Web ASP.NET.

L'exemple suivant montre comment créer HyperLinkColumn établissant un lien vers une page séparée.

RemarqueRemarque

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.

Visual Basic
<%@ 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>
C#
<%@ 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.

Visual Basic
<%@ 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>

C#
<%@ 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>

.NET Framework

Pris en charge dans : 4, 3.5, 3.0, 2.0, 1.1, 1.0

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.
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.
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2012 Microsoft. Tous droits réservés. Conditions d'utilisation | Marques | Confidentialité
Page view tracker