Bonjour.
Je vous met le code de mon composant dans lequel je créer un DataGrid en dynamique auquel j'affecte l'evenement OnSortCommand.
Je voulais savoir si je le faisais au bon moment ou pas...
Merci d'avance.
Le code :
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 namespace MyNameSpace { /// <summary> /// Résumé de la description de WebControl1. /// </summary> [DefaultProperty("Text"), ToolboxData("<{0}:WebControl1 runat=server></{0}:WebControl1>")] public class Affichage : MyCompo { private DataGrid DgResult; public Affichage() : base() { DgResult = new DataGrid(); DgResult.AutoGenerateColumns = false; DgResult.AllowSorting = true; DgResult.EnableViewState = true; DgResult.ItemDataBound += new DataGridItemEventHandler(DG_ItemDataBound); DgResult.SortCommand += new DataGridSortCommandEventHandler(DG_SortCommand); } protected override void CreateChildControls() { // Le code .... BindData(); } public void BindData() { /* Remplissage de la DataGrid */ DgResult.DataSource = DsResult; DgResult.Columns.Clear(); BoundColumn col = new BoundColumn(); col.HeaderText = "Un"; col.DataField = "UN"; col.SortExpression = "UN"; DgResult.Columns.Add(col); col = new BoundColumn(); col.HeaderText = "Deux"; col.DataField = "DEUX"; col.SortExpression = "DEUX"; DgResult.Columns.Add(col); col = new BoundColumn(); col.HeaderText = "Trois"; col.DataField = "TROIS"; col.SortExpression = "TROIS"; DgResult.Columns.Add(col); DgResult.DataBind(); Controls.Add(DgResult); } protected void DG_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) { if (SortExp == e.SortExpression) SortExp = e.SortExpression + " DESC"; else { if ((SortExp != "") && (SortExp != null)) { string[] MyArray = SortExp.Split(new char[] {' '}); if (MyArray[0] != e.SortExpression) SortExp = e.SortExpression; else SortExp = ""; } else SortExp = e.SortExpression; } CreateChildControls(); } }
Partager