A new gridview is encapsulated, and the following functions are supported: 1. Select a record in the checkbox and specify the position of the checkbox.
2. list, dataset, and able sorting are supported.
3. the header icon appears during sorting.
4. It encapsulates pageindexchanged and databind, and does not need to be written on every page.
5. Supports paging controls such as SQL paging and aps tutorial netpager. Note: many functions are not added, because a lightweight gridview is required to generate near-Possible code. In addition, the highlighted feature is implemented by jquery. Therefore, the jquery Runtime Library is required for use. Code 1: Secondary object to implement sort sorting. (In fact, this part of the function can be implemented using linq, which is much simpler. When this class has been used for a long time, I am too lazy to change it)
1 using system;
2 using system. collections;
3 using system. collections. generic;
4 using system. reflection;
5
6 namespace xxware. xxcontrols
7 {
8 public class reverser <t>: icomparer <t>
9 {
10 private type _ type = null;
11 private reverserinfo info;
12
13 /// <summary>
14 // Constructor
15 /// </summary>
16 /// <param name = "type"> compare the class types </param>
17 // <param name = "name"> compare the property name of an object </param>
18 /// <param name = "direction"> comparison direction (ascending/descending) </param>
19 public reverser (type _ type, string _ name, string _ direction)
20 {
21 this. _ type = _ type;
22 this.info. name = _ name;
23 this.info. direction = _ direction. tolower ();
24}
25
26 /// <summary>
27 // Constructor
28 /// </summary>
29 // <param name = "classname"> name of the class to be compared </param>
30 /// <param name = "name"> compare the property name of an object </param>
31 // <param name = "direction"> comparison direction (ascending/descending) </param>
32 public reverser (string _ classname, string _ name, string _ direction)
33 {
34 try
35 {
36 this. _ type = type. gettype (_ classname, true );
37 this.info. name = _ name;
38 this.info. direction = _ direction. tolower ();
39}
40 catch (exception e)
41 {
42 throw new exception (e. message );
43}
44
45}
46
47 // <summary>
48 // Constructor
49 // </summary>
50 /// <param name = "t"> compare instances </param>
51 // <param name = "name"> name of the property of the object to be compared </param>
52 // <param name = "direction"> comparison direction (ascending/descending) </param>
53 public reverser (t _ t, string _ name, string _ direction)
54 {
55 this. _ type = _ t. gettype ();
56 this.info. name = _ name;
57 this.info. direction = _ direction;
58}
59
60 int icomparer <t>. compare (t t1, t t2)
61 {
62 object x = this. _ type. invokemember (this.info. name, bindingflags. public | bindingflags. instance | bindingflags. getproperty, null, t1, null );
63 object y = this. _ type. invokemember (this.info. name, bindingflags. public | bindingflags. instance | bindingflags. getproperty, null, t2, null );
64
65 if (this.info. direction! = "Asc ")
66 swap (ref x, ref y );
67 return (new caseinsensitivecomparer (). compare (x, y );
68}
69
70 void swap (ref object x, ref object y)
71 {
72 object tmp = x;
73 x = y;
74 y = tmp;
75}
76}
77 public struct reverserinfo
78 {
79 public enum target
80 {
81 customer = 0,
82 from,
83 field,
84 server
85}
86
87 public string name;
88 public string direction; // asc, desc;
89 public target;
90}
91} Code 2: template Class, used to generate the checkbox Column
1 using system;
2 using system. web;
3 using system. web. ui;
4 using system. web. ui. webcontrols;
5
6 namespace xxware. xxcontrols
7 {
8 # region selector template
9 public class xxgridcolumntemplate: itemplate
10 {
11 public void instantiatein (control container)
12 {
13 checkbox cb = new checkbox ();
14 cb. id = "fargv_columnselector ";
15 cb. clientidmode = clientidmode. autoid;
16 cb.css tutorial class = "far_rowsselector ";
17 container. controls. addat (0, cb );
18}
19}
20
21 public class xxgridheadertemplate: itemplate
22 {
23 public void instantiatein (control container)
24 {
25 system.web.ui.htmlcontrols.html inputcheckbox selectall = new system.web.ui.htmlcontrols.html inputcheckbox ();
26 selectall. id = "fargv_columnselectorall ";
27 selectall. clientidmode = clientidmode. static;
28 selectall. attributes ["onclick"] = "fargridview_columnselectorall ();";
29 container. controls. add (selectall );
30}
31}
32
33 # endregion
34
35}