IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

treeview avec des liens hypertext


Sujet :

ASP.NET

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Août 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2008
    Messages : 97
    Points : 51
    Points
    51
    Par défaut treeview avec des liens hypertext
    Bonsoir,

    voilà, je suis en train de programmer un treeview, afin d'avoir une arborescence de mes produits classés par catégorie.

    Niveau code, ça donne ça pour la partie design:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
            <asp:TreeView 
                ID="Arborescence_soins" 
                PopulateNodesFromClient="true" 
                OnTreeNodePopulate="remplissagenoeud" 
                runat="server">
            <Nodes>
                <asp:TreeNode 
                    Text="prod_liste" 
                    SelectAction="Expand" 
                    PopulateOnDemand="true">
                </asp:TreeNode>
            </Nodes>
            </asp:TreeView>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    et cela pour la partie code behind :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
     
        Sub remplissagenoeud(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
     
            ' Call the appropriate method to populate a node at a particular level.
            Select Case e.Node.Depth
     
                Case 0
                    ' Populate the first-level nodes.
                    PopulateCategories(e.Node)
     
                Case 1
                    ' Populate the second-level nodes.
                    PopulateProducts(e.Node)
     
                Case Else
                    ' Do nothing.
     
            End Select
     
        End Sub
     
        Function RunQuery(ByVal QueryString As String) As DataSet
     
            ' Declare the connection string. This example uses Microsoft SQL Server 
            ' and connects to the Northwind sample database.
            Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("BIOTYFULConnectionString").ConnectionString
     
            Dim DBConnection As SqlConnection = New SqlConnection(ConnectionString)
            Dim DBAdapter As SqlDataAdapter
            Dim ResultsDataSet As DataSet = New DataSet
     
            Try
     
                ' Run the query and create a DataSet.
                DBAdapter = New SqlDataAdapter(QueryString, DBConnection)
                DBAdapter.Fill(ResultsDataSet)
     
                ' Close the database connection.
                DBConnection.Close()
     
            Catch ex As Exception
     
                ' Close the database connection if it is still open.
                If DBConnection.State = ConnectionState.Open Then
     
                    DBConnection.Close()
     
                End If
     
                Label1.Text = "Unable to connect to the database."
     
            End Try
     
            Return ResultsDataSet
     
        End Function
     
        Sub PopulateProducts(ByVal node As TreeNode)
     
            ' Query for the products of the current category. These are the values
            ' for the third-level nodes.
            Dim ResultSet As DataSet = RunQuery("SELECT ID_produit, NOM_produit FROM PRODUITS Where CAT_produit =" & node.Value)
     
            ' Create the third-level nodes.
            If ResultSet.Tables.Count > 0 Then
     
                ' Iterate through and create a new node for each row in the query results.
                ' Notice that the query results are stored in the table of the DataSet.
                Dim row As DataRow
     
                For Each row In ResultSet.Tables(0).Rows
     
                    ' Create the new node.
                    Dim NewNode As TreeNode = New TreeNode(row("NOM_produit").ToString(), row("ID_produit").ToString())
     
                    ' Set the PopulateOnDemand property to false, because these are leaf nodes and
                    ' do not need to be populated.
                    NewNode.PopulateOnDemand = False
     
                    ' Set additional properties for the node.
                    NewNode.SelectAction = TreeNodeSelectAction.None
     
                    ' Add the new node to the ChildNodes collection of the parent node.
                    node.ChildNodes.Add(NewNode)
     
                Next
     
            End If
     
        End Sub
     
        Sub PopulateCategories(ByVal node As TreeNode)
     
            ' Query for the product categories. These are the values
            ' for the second-level nodes.
            Dim ResultSet As DataSet = RunQuery("Select ID_categorie, NOM_categorie From CATEGORIE")
     
            ' Create the second-level nodes.
            If ResultSet.Tables.Count > 0 Then
     
                ' Iterate through and create a new node for each row in the query results.
                ' Notice that the query results are stored in the table of the DataSet.
                Dim row As DataRow
     
                For Each row In ResultSet.Tables(0).Rows
     
                    ' Create the new node. Notice that the CategoryId is stored in the Value property 
                    ' of the node. This will make querying for items in a specific category easier when
                    ' the third-level nodes are created. 
                    Dim newNode As TreeNode = New TreeNode()
                    newNode.Text = row("NOM_categorie").ToString()
                    newNode.Value = row("ID_categorie").ToString()
     
                    ' Set the PopulateOnDemand property to true so that the child nodes can be 
                    ' dynamically populated.
                    newNode.PopulateOnDemand = True
     
                    ' Set additional properties for the node.
                    newNode.SelectAction = TreeNodeSelectAction.Expand
     
                    ' Add the new node to the ChildNodes collection of the parent node.
                    node.ChildNodes.Add(newNode)
     
                Next
     
            End If
     
        End Sub
    Jusqu'à là, tout fonctionne très bien.

    Je souhaite maintenant, que chaque nom de produit soit un lien, qui me permet d'appeler une fonction qui me remplirai un detailview avec les infos sur le produit en question.

    Mon problème c'est que je ne vois pas du tout comme attribuer dynamiquement un lien à chacun de mes produits avec comme valeur l'id de mon produit que je pourrai alors utiliser dans une requete sql afin de récupérer les infos sur ce produit.

    Si quelqu'un pouvait me mettre sur la piste, cela serait génial

    Cordialement,
    Tommy

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Août 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2008
    Messages : 97
    Points : 51
    Points
    51
    Par défaut
    Re-bonsoir,

    après avoir posté mon problème, je suis tombé sur la propriété "selectaction" qui semble-t'il va pouvoir répondre à ma requête.

    Bonne nuit,
    Tommy

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 11/05/2011, 13h45
  2. [XL-2002] Ecrire des liens hypertexte avec des chemins relatifs
    Par Invité dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 22/11/2010, 15h36
  3. [Toutes versions] Creer des liens hypertexte avec un UserForm
    Par J-c pourexel dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 19/05/2010, 17h48
  4. [XL-2003] Excel et ouvrir des photos avec un lien hypertexte
    Par Alain53 dans le forum Excel
    Réponses: 2
    Dernier message: 22/03/2010, 10h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo