Bonjour à tous ,


Actuellement sur le développement d'un site web en asp, on m'a chargé de créer une arborescence pour faire apparaître les différentes infos de la base de données. C'est à dire, que dans mon arbre je devrais avoir des pôles qui contiennent des départements qui eux contiennent des équipes etc...

Pour cela, j'ai choisi l'objet treeview qui correspond le mieux à mes attendes.

voici mon code actuel :


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
 
 
    protected void Button_tre_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection();
        cn.ConnectionString = @"Data Source=B0168;Initial Catalog=annuaire;Integrated Security=True";
 
        DataSet mondataPole = new DataSet() ;
        SqlDataAdapter sqaPole = new SqlDataAdapter();
        sqaPole.SelectCommand = new SqlCommand("SELECT ID, LIBELLEFR FROM POLES ", cn);
        sqaPole.Fill(mondataPole, "POLES");
 
        DataSet mondataDep = new DataSet();
        SqlDataAdapter sqaDep = new SqlDataAdapter();
        sqaDep.SelectCommand = new SqlCommand("SELECT IDPOLE, NOMSERVFR FROM DEP ", cn);
        sqaDep.Fill(mondataDep, "DEP");
 
        DataSet mondataEq = new DataSet();
        SqlDataAdapter sqaEq = new SqlDataAdapter();
        sqaEq.SelectCommand = new SqlCommand("SELECT ID, IDDEP, LIBELLEFR FROM EQUIPE ", cn);
        sqaEq.Fill(mondataEq, "EQUIPE");
 
           int i = 0;
            int x = 0;
           string idPole;
           string idPole_Dep;
           string idEq;
           string idDep_Eq;
 
        foreach (DataTable dtPole in mondataPole.Tables)
        {
 
            foreach(DataRow lPole in dtPole.Rows)
            {
 
                idPole =  lPole["ID"].ToString();
                TreeView1.Nodes.Add(new TreeNode(lPole["LIBELLEFR"].ToString()));
 
                foreach (DataTable dtDep in mondataDep.Tables)
                {
 
                    foreach (DataRow lDep in dtDep.Rows)
                    {
                        idPole_Dep = lDep["IDPOLE"].ToString();
                        if (idPole == idPole_Dep)
                        {
                            TreeView1.Nodes[i].ChildNodes.Add(new TreeNode(lDep["NOMSERVFR"].ToString()));
 
                        }
 
                     }
 
                    foreach (DataTable dtEq in mondataEq.Tables)
                        {
 
                            foreach (DataRow lEq in dtEq.Rows)
                            {
 
                                idEq = lEq["IDDEP"].ToString();
                                idDep_Eq = lEq["ID"].ToString();
                                if (idEq == idDep_Eq)
                                {
                                    TreeView1.Nodes[x].ChildNodes.Add(new TreeNode(lEq["LIBELLEFR"].ToString()));
 
                                }
 
                            }
 
                        }
                        x++; 
                    }
                i++;
            }
 
        }
 
 
    }
 
}
La où je rencontre des difficultés, c'est pour afficher les équipes contenues dans les départements. J'ai essayé plusieurs possibilité mais rien à faire je reste bloqué. Si vous avez des propositions, je suis preneur.

Merci à vous