Bonjour,

j'ai un GRAND besoin d'aide et j'espère que quelqu'un ici aura la sympathie et le temps de me répondre .

Voilà deux semaines que je suis en stage et que j'essaie de faire du .net avec du jQuery notamment.

En ce moment, je suis sur la construction d'un tableau dans une page .aspx. Pour l'instant j'arrive à obtenir ceci :



Concretement, c'est un <asp:Table> que je construit à partir d'une base de données avec du code behind C#. On m'a souvent conseiller d'utiliser des gridview ou datagrid à la place mais les cellules de ce tableau ont une particularité dont je ne sais pas si elle est compatible avec les gridviw ou les datagrid. En effet, j'ajoute chaque cellule une par une en spécifiant des attribut "class" et "rowspan/colspan" quand c'est necessaire. Et je ne sais pas s'il serait possible de faire ça avec gridview ou datagrid. J'ai besoin de ces multiple "class" pour traité les cellules en jQuery (notemment pour pouvoir faire du drag&drop).

Voici un bout de mon code qui montre comment je crée ce tableau :

Code .aspx :

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
<asp:Table ID="tabG" runat="server" GridLines="Both">
 
<asp:TableHeaderRow ID="TableHeaderRow1" runat="server" TableSection="TableHeader">
                            <asp:TableCell ID="idTitreTabG_CheckB" RowSpan="3"></asp:TableCell>
                            <asp:TableCell ID="idTitreTabG_NumOF" RowSpan="2">
                                <asp:Label ID="lbTabG_TitreNumOF" Text="N° OF" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell RowSpan="2">
                                <asp:Label ID="lbTabG_TitreSeqOF" Text="Seq OF" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell RowSpan="2">
                                <asp:Label ID="lbTabG_TitreArt" Text="Article" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell RowSpan="2">
                                <asp:Label ID="lbTabG_TitreQtePrevue" Text="Qté OF prévue" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell RowSpan="2">
                                <asp:Label ID="lbTabG_TitreQteRevue" Text="Qté OF revue" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell RowSpan="2">
                                <asp:Label ID="lbTabG_TitreComp" Text="Composant" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell RowSpan="2">
                                <asp:Label ID="lbTabG_TitreRestant" Text="Restant à assigner" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell ColumnSpan="3">
                                <asp:Label ID="lbTabG_TitreAssignHU" Text="Assignation HU" runat="server"></asp:Label>
                            </asp:TableCell>
                        </asp:TableHeaderRow>
 
                        <asp:TableHeaderRow ID="TableHeaderRow2" runat="server" TableSection="TableHeader">
                            <asp:TableCell>
                                <asp:Label ID="lbTabG_TitreQteTotale" Text="Qté totale" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell>
                                <asp:Label ID="lbTabG_TitreNumHU" Text="N° HU" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                            <asp:TableCell>
                                <asp:Label ID="lbTabG_TitreQte" Text="Quantité" runat="server"></asp:Label> <br />
                            </asp:TableCell>
                        </asp:TableHeaderRow>
 
                        <asp:TableHeaderRow ID="TableHeaderRow5" runat="server" TableSection="TableHeader">
                            <asp:TableCell>
                                <asp:ImageButton ID="ibTabG_TitreNumOF_Fleche" runat="server" PostBackUrl="~/Test.aspx?nomColG=cod_wo&order=desc" ImageUrl="~/Images/bas.jpg" />
                            </asp:TableCell>
                            <asp:TableCell>
                                <asp:ImageButton ID="ibTabG_TitreSeqOF_Fleche" runat="server" PostBackUrl="~/Test.aspx?nomColG=dat_sequence&order=desc" ImageUrl="~/Images/bas.jpg" />
                            </asp:TableCell>
                            <asp:TableCell>
                                <asp:ImageButton ID="ibTabG_TitreArt_Fleche" runat="server" PostBackUrl="~/Test.aspx?nomColG=article&order=desc" ImageUrl="~/Images/bas.jpg" />
                            </asp:TableCell>
                            <asp:TableCell>
                                <asp:ImageButton ID="ibTabG_TitreQtePrevue_Fleche" runat="server" PostBackUrl="~/Test.aspx?nomColG=wo_qty&order=desc" ImageUrl="~/Images/bas.jpg" />
                            </asp:TableCell>
                            <asp:TableCell>
                                <asp:ImageButton ID="ibTabG_TitreQteRevue_Fleche" runat="server" PostBackUrl="~/Test.aspx?nomColG=qty_revue&order=desc" ImageUrl="~/Images/bas.jpg" />
                            </asp:TableCell>
                            <asp:TableCell>
                                <asp:ImageButton ID="ibTabG_TitreComposant_Fleche" runat="server" PostBackUrl="~/Test.aspx?nomColG=composant&order=desc" ImageUrl="~/Images/bas.jpg" />
                            </asp:TableCell>
                            <asp:TableCell>
                                <asp:ImageButton ID="ibTabG_TitreRestant_Fleche" runat="server" PostBackUrl="~/Test.aspx?nomColG=restant_a_assigner&order=desc" ImageUrl="~/Images/bas.jpg" />
                            </asp:TableCell>
                            <asp:TableCell>
                            </asp:TableCell>
                            <asp:TableCell>
                            </asp:TableCell>
                            <asp:TableCell>
                            </asp:TableCell>
 
                        </asp:TableHeaderRow>
 
</asp:Table>
Cette partie crée les en-têtes de colonnes

Code behind en c# qui complète le tableau :

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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
protected void setTabAssignationOF(OracleConnection oConnexion, string reqOF)
        {
 
            OracleCommand cmd = new OracleCommand(reqOF);
            cmd.Connection = oConnexion;
 
            OracleDataReader reader = cmd.ExecuteReader();
 
            int cpt = 0;
            int nbLignesCurrentOF = 0;
            int numLigne = 0;
            string idCurrentOF = "";
 
            List<TableRow> lignes = new List<TableRow>();
 
            while (reader.Read())
            {
 
                TableRow nouvelleLigne = new TableRow();
 
                CheckBox controlCB = new CheckBox();
                TableCell checkB = new TableCell();
                TableCell numOF = new TableCell();
                TableCell seqOF = new TableCell();
                TableCell art = new TableCell();
                TableCell qtePrevue = new TableCell();
                TableCell qteRevue = new TableCell();
                TableCell composant = new TableCell();
                TableCell restant = new TableCell();
                TableCell qteTotale = new TableCell();
                TableCell numHU = new TableCell();
                TableCell qteHU = new TableCell();
 
                if(reader.GetValue(0).ToString() == idCurrentOF){
                    TableRow ligneModifie = new TableRow();
 
                    nbLignesCurrentOF = nbLignesCurrentOF + 1;
 
                    lignes[numLigne].Cells[0].RowSpan = nbLignesCurrentOF;
                    lignes[numLigne].Cells[1].RowSpan = nbLignesCurrentOF;
                    lignes[numLigne].Cells[2].RowSpan = nbLignesCurrentOF;
                    lignes[numLigne].Cells[3].RowSpan = nbLignesCurrentOF;
                    lignes[numLigne].Cells[4].RowSpan = nbLignesCurrentOF;
                    lignes[numLigne].Cells[5].RowSpan = nbLignesCurrentOF;
                    lignes[numLigne].Cells[6].RowSpan = nbLignesCurrentOF;
                    lignes[numLigne].Cells[7].RowSpan = nbLignesCurrentOF;
 
 
                    // nouvelles lignes
                    string identifiant = lignes[numLigne].Cells[1].ID;
 
                    qteTotale.Text = reader.GetValue(9).ToString();
                    qteTotale.Attributes.Add("class", "tabG_qteTotale donneesOF " + lignes[numLigne].Cells[1].Text);
                    qteTotale.Attributes.Add("value", qteTotale.Text);
                    qteTotale.ID = "qteT" + identifiant + "_" + nbLignesCurrentOF;
 
                    numHU.Text = reader.GetValue(10).ToString();
                    numHU.Attributes.Add("class", "tabG_numHU donneesOF " + lignes[numLigne].Cells[1].Text + " " + numHU.Text.Replace(" ", "_"));
                    numHU.Attributes.Add("value", numHU.Text);
                    numHU.ID = "numHU" + identifiant + "_" + nbLignesCurrentOF;
                    numHU.Attributes.Add("onClick", "onClick_cellule(\"" + numHU.Text + "\",\"" + numHU.Text.Replace(" ", "_") + "\");");
 
                    qteHU.Text = reader.GetValue(11).ToString();
                    qteHU.Attributes.Add("class", "tabG_qteHU donneesOF " + lignes[numLigne].Cells[1].Text);
                    qteHU.Attributes.Add("value", qteHU.Text);
                    qteHU.ID = "qteH" + identifiant + "_" + nbLignesCurrentOF;
 
                    nouvelleLigne.Cells.Add(qteTotale);
                    nouvelleLigne.Cells.Add(numHU);
                    nouvelleLigne.Cells.Add(qteHU);
 
                    lignes.Add(nouvelleLigne);
                }
                else{
                    numLigne = numLigne + nbLignesCurrentOF;
                    nbLignesCurrentOF = 1;
 
                    idCurrentOF = reader.GetValue(0).ToString();
 
                    // la premiere colonne contient une checkbox avec le numéro de l'OF
                    checkB.ID = "cb" + reader.GetValue(0).ToString() + cpt;
                    checkB.Controls.Add(controlCB);
                    checkB.Attributes.Add("class", "tabG_checkB donneesOF " + reader.GetValue(0).ToString());
                    checkB.Attributes.Add("value", "n");
 
                    // les colonnes suivantes
                    numOF.Text = reader.GetValue(0).ToString();
                    numOF.Attributes.Add("class", "tabG_numOF donneesOF " + numOF.Text + " " + numOF.Text.Replace(" ","_"));
                    numOF.Attributes.Add("value", numOF.Text);
                    numOF.ID = numOF.Text;
                    numOF.Attributes.Add("onClick", "onClick_cellule(\"" + numOF.Text + "\",\"" + numOF.Text.Replace(" ","_") + "\");");
 
                    seqOF.Text = reader.GetValue(3).ToString();
                    seqOF.Attributes.Add("class", "tabG_seqOF donneesOF " + numOF.Text);
                    seqOF.Attributes.Add("value", seqOF.Text);
                    seqOF.ID = "seqOF" + numOF.ID;
 
                    art.Text = reader.GetValue(4).ToString();
                    art.Attributes.Add("class", "tabG_art donneesOF " + numOF.Text);
                    art.Attributes.Add("value", art.Text);
                    art.ID = "art" + numOF.ID;
 
                    qtePrevue.Text = reader.GetValue(5).ToString();
                    qtePrevue.Attributes.Add("class", "tabG_qtePrevue donneesOF " + numOF.Text);
                    qtePrevue.Attributes.Add("value", qtePrevue.Text);
                    qtePrevue.ID = "qteP" + numOF.ID;
 
                    qteRevue.Text = reader.GetValue(6).ToString();
                    qteRevue.Attributes.Add("class", "tabG_qteRevue donneesOF " + numOF.Text);
                    qteRevue.Attributes.Add("value", qteRevue.Text);
                    qteRevue.ID = "qteR" + numOF.ID;
 
                    composant.Text = reader.GetValue(7).ToString();
                    composant.Attributes.Add("class", "tabG_composant donneesOF " + numOF.Text + " " + composant.Text.Replace(" ","_"));
                    composant.Attributes.Add("value", composant.Text);
                    composant.ID = "comp" + numOF.ID;
                    composant.Attributes.Add("onClick", "onClick_cellule(\"" + composant.Text + "\",\"" + composant.Text.Replace(" ","_") + "\");");
 
                    restant.Text = reader.GetValue(8).ToString();
                    restant.Attributes.Add("class", "tabG_restant donneesOF " + numOF.Text);
                    restant.Attributes.Add("value", restant.Text);
                    restant.ID = "restant" + numOF.ID;
 
                    qteTotale.Text = reader.GetValue(9).ToString();
                    qteTotale.Attributes.Add("class", "tabG_qteTotale donneesOF " + numOF.Text);
                    qteTotale.Attributes.Add("value", qteTotale.Text);
                    qteTotale.ID = "qteT" + numOF.ID + "_1";
 
                    numHU.Text = reader.GetValue(10).ToString();
                    numHU.Attributes.Add("class", "tabG_numHU donneesOF " + numOF.Text + " " + numHU.Text.Replace(" ", "_"));
                    numHU.Attributes.Add("value", numHU.Text);
                    numHU.ID = "numHU" + numOF.ID + "_1";
                    numHU.Attributes.Add("onClick", "onClick_cellule(\"" + numHU.Text + "\",\"" + numHU.Text.Replace(" ","_") + "\");");
 
                    qteHU.Text = reader.GetValue(11).ToString();
                    qteHU.Attributes.Add("class", "tabG_qteHU donneesOF " + numOF.Text);
                    qteHU.Attributes.Add("value", qteHU.Text);
                    qteHU.ID = "qteH" + numOF.ID + "_1";
 
                    nouvelleLigne.Cells.Add(checkB);
                    nouvelleLigne.Cells.Add(numOF);
                    nouvelleLigne.Cells.Add(seqOF);
                    nouvelleLigne.Cells.Add(art);
                    nouvelleLigne.Cells.Add(qtePrevue);
                    nouvelleLigne.Cells.Add(qteRevue);
                    nouvelleLigne.Cells.Add(composant);
                    nouvelleLigne.Cells.Add(restant);
                    nouvelleLigne.Cells.Add(qteTotale);
                    nouvelleLigne.Cells.Add(numHU);
                    nouvelleLigne.Cells.Add(qteHU);
 
                    lignes.Add(nouvelleLigne);
                }
 
 
 
                cpt++;
            }
 
            for (int i = 0; i < lignes.Count; i++)
            {
                tabG.Rows.Add(lignes[i]);
            }
        }
Comme vous pouvez le voir, chaque cellule possède de nombreux attribut "class" ou parfois "rowspan".



Jusqu'à aujourd'hui ça allait à peu près, sauf que je me heurte maintenant à quelques problèmes :

Avec ce système, les checkbox ne sont pas lié aux lignes, ce qui signifie que si par exemple je coche la checkbox de la ligne 3 et que je fait un tri sur la colonne 2. Ce sera toujours la checkbox de la ligne 3 qui sera coché mais cela ne correspondra plus à la même ligne.

Pensez-vous qu'il y aurait une solution, une autre méthode que je devrait utiliser ? Merci d'avance =D