Bonjour,
J'utilise un gridview (ASP 2.0) j'ai implemente manuelement le tri quand je clique sur les headers des colonnes avec le flip/flop ASC/DESC tout cela fonctionne bien seulement... quand j'affiche la seconde page de mon gridview le sorting repasse automatiquement a ASC...
mon code :
Des idees ???
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 //je fais persister le sortdirection dans le viewstate protected SortDirection CurrentDirection { get { if (this.ViewState["CurrentDirection"] != null) { return (SortDirection)this.ViewState["CurrentDirection"]; } return SortDirection.Ascending; } set { this.ViewState["CurrentDirection"] = value; } } protected void gvJob_PageIndexChanging(object sender, GridViewPageEventArgs e) { //ici je ne sais pas quoi faire pour garder le sortdirection a DESC il repasse automatiquement a ASC gvJob.PageIndex = e.NewPageIndex; gvJob.DataBind(); } protected void gvJob_Sorting(object sender, GridViewSortEventArgs e) { this.CurrentDirection = CurrentDirection == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending; DataTable dataTable = gvJob.DataSource as DataTable; if (dataTable != null) { DataView dataView = new DataView(dataTable); dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(CurrentDirection); gvJob.DataSource = dataView; gvJob.DataBind(); } } private string ConvertSortDirectionToSql(SortDirection sortDirection) { string newSortDirection = String.Empty; switch (sortDirection) { case SortDirection.Ascending: newSortDirection = "ASC"; break; case SortDirection.Descending: newSortDirection = "DESC"; break; } return newSortDirection; }
(pardon pour les accents => clavier qwerty inside...)
merci d'avance
Partager