Bonjour,


J'ai un pblm avec la personnalisation d'un gridview (affichage de lignes separator et de ligne datarow complémentaires pour avoir aérer la page).

L'affichage est ok lors de l'initialisation. Par contre, la mise en forme disparait quand les données sont splittées sur plusieurs page et que j'affiche une page autre que la première voire quand je reviens après coup sur la 1ère page.
J'ai suivi le principe présente par le site msdn ci-après : http://msdn.microsoft.com/en-us/libr...srtuics_topic4

Le principe consiste à surcharger la méthode RENDER de ma page. Quand je suis en mode DEBUG, cette méthode est pourtant systématiquement bien exécutée que ce soit lors de l'init. ou par la suite lors de l'affichage d'une page autre.

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
 
        protected override void Render(HtmlTextWriter writer)
        {
            Boolean changePtf=true;
            int index;
 
            // Reference the Table the GridView has been rendered into
            Table gvTable = (Table)this.gvListe.Controls[0];
 
 
            //foreach (TableRow gvRow in gvTable.Rows)
            foreach(GridViewRow gvRow in gvListe.Rows)
            {
                //index = gvTable.Rows.GetRowIndex(gvRow);
                index = gvTable.Rows.GetRowIndex(gvRow);
 
                //int currentPtf = Convert.ToInt32(this.gvListe.DataKeys[row.RowIndex].Values[1]);
                //int currentPtf = Convert.ToInt32(this.gvListe.DataKeys[realIndex].Values[1]);
                //String currentPtf = gvRow.Cells[1].Text;
                String strPtf = ((Label)gvRow.FindControl("lblPtf")).Text;
 
 
                /*
                if(currentCategory != lastCategory)
                {
                    GridViewRow groupHeaderRow = 
                                new GridViewRow(realIndex, realIndex, DataControlRowType.Separator, DataControlRowState.Normal);
 
                    TableCell newCell = new TableCell();
                    newCell.ColumnSpan = this.productsGrid.Columns.Count;
                    newCell.BackColor = System.Drawing.Color.FromArgb(233, 229, 229);
                    newCell.ForeColor = System.Drawing.Color.DarkGray;
                    newCell.Font.Bold = true;
 
                    switch(currentCategory)
                    {
                        case 515:
                        case 517:
                            newCell.Text = "Home Products";
                            break;
                        default:
                            newCell.Text = "Business Products";
                            break;
                    }
                }
                */
 
 
                if (!String.IsNullOrEmpty(strPtf) & index != 1)
                {
                    changePtf = true;
 
                    TableCell newCell = new TableCell();
                    newCell.ColumnSpan = this.gvListe.Columns.Count;
                    //newCell.CssClass = "gridviewSeparator";
                    newCell.BackColor = System.Drawing.Color.FromArgb(233, 229, 229);
                    //newCell.ForeColor = System.Drawing.Color.DarkGray;
                    newCell.Height = 10;
 
                    //GridViewRow groupHeaderRow = new GridViewRow(realIndex, realIndex, DataControlRowType.Separator, DataControlRowState.Normal);
                    GridViewRow separatorRow = new GridViewRow(index, index, DataControlRowType.Separator, DataControlRowState.Normal);
                    separatorRow.Cells.Add(newCell);
                    //separatorRow.CssClass = "gridviewSeparator";
 
                    gvTable.Controls.AddAt(index, separatorRow);
                    //gvTable.Rows.AddAt(index, separatorRow);
 
                }
                else
                {
                    changePtf = false;
                }
 
                //((Label)gvRow.FindControl("lblTituDenom_bis")).Text = "toto";
                //((Label)gvRow.FindControl("lblTituDenom_bis")).Visible = true;
                //((Label)gvRow.FindControl("lblTituDenom")).Visible = false;
                TableCell newCell1 = new TableCell();
                newCell1.ColumnSpan = 4;
                newCell1.Text = ((Label)gvRow.FindControl("lblPtfLibelle")).Text;
                newCell1.HorizontalAlign = HorizontalAlign.Left;
 
                TableCell newCell2 = new TableCell();
                newCell2.ColumnSpan = 4;
                newCell2.Text = ((Label)gvRow.FindControl("lblTituDenom")).Text;
                newCell2.HorizontalAlign = HorizontalAlign.Left;
 
                TableCell newCell3 = new TableCell();
                newCell3.ColumnSpan = 3;
                newCell3.Text = ((Label)gvRow.FindControl("lblRPDenom")).Text;
                newCell3.HorizontalAlign = HorizontalAlign.Left;
 
 
                //GridViewRow groupHeaderRow = new GridViewRow(realIndex, realIndex, DataControlRowType.Separator, DataControlRowState.Normal);
                GridViewRow newRow = new GridViewRow(index, index, DataControlRowType.DataRow, DataControlRowState.Normal);
                newRow.Cells.Add(newCell1);
                newRow.Cells.Add(newCell2);
                newRow.Cells.Add(newCell3);
                //separatorRow.CssClass = "gridviewSeparator";
 
 
                int newIndex;
                if (index == 1)
                {
                    newIndex = index + 1;
                }
                else
                {
                    if (changePtf)
                    {
                        newIndex = index + 2;
                    }
                    else
                    {
                        newIndex = index + 1;
                    }
                }
 
 
                gvTable.Controls.AddAt(newIndex, newRow);
                //gvTable.Rows.AddAt(newIndex, newRow);
 
 
            }
 
 
            //gvListe.RenderControl(writer);
 
            // Add code to manipulate the GridView control hierarchy
            base.Render(writer);
        }



Si qqun a une piste...

Laurent