-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDefault.aspx.cs
102 lines (96 loc) · 3.76 KB
/
Default.aspx.cs
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
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using DevExpress.Web.Data;
using DevExpress.Web;
public partial class _Default: System.Web.UI.Page {
protected List<GridDataItem> GridData {
get {
var key = "34FAA431-CF79-4869-9488-93F6AAE81263";
if (!IsPostBack || Session[key] == null)
Session[key] = Enumerable.Range(1, 50).Select(i => new GridDataItem {
ID = i,
Mon = i * 10 % 3,
Tue = i * 5 % 3,
Wen = i % 2
}).ToList();
return (List<GridDataItem>)Session[key];
}
}
protected void Page_Load(object sender, EventArgs e) {
Grid.DataSource = GridData;
Grid.DataBind();
}
protected void Grid_RowInserting(object sender, ASPxDataInsertingEventArgs e) {
InsertNewItem(e.NewValues);
CancelEditing(e);
}
protected void Grid_RowUpdating(object sender, ASPxDataUpdatingEventArgs e) {
UpdateItem(e.Keys, e.NewValues);
CancelEditing(e);
}
protected void Grid_RowDeleting(object sender, ASPxDataDeletingEventArgs e) {
DeleteItem(e.Keys, e.Values);
CancelEditing(e);
}
protected void Grid_BatchUpdate(object sender, ASPxDataBatchUpdateEventArgs e) {
foreach (var args in e.InsertValues)
InsertNewItem(args.NewValues);
foreach (var args in e.UpdateValues)
UpdateItem(args.Keys, args.NewValues);
foreach (var args in e.DeleteValues)
DeleteItem(args.Keys, args.Values);
e.Handled = true;
}
protected GridDataItem InsertNewItem(OrderedDictionary newValues) {
var item = new GridDataItem() { ID = GridData.Count };
LoadNewValues(item, newValues);
GridData.Add(item);
return item;
}
protected GridDataItem UpdateItem(OrderedDictionary keys, OrderedDictionary newValues) {
var id = Convert.ToInt32(keys["ID"]);
var item = GridData.First(i => i.ID == id);
LoadNewValues(item, newValues);
return item;
}
protected GridDataItem DeleteItem(OrderedDictionary keys, OrderedDictionary values) {
var id = Convert.ToInt32(keys["ID"]);
var item = GridData.First(i => i.ID == id);
GridData.Remove(item);
return item;
}
protected void LoadNewValues(GridDataItem item, OrderedDictionary values) {
item.Mon = Convert.ToInt32(values["Mon"]);
item.Tue = Convert.ToInt32(values["Tue"]);
item.Wen = Convert.ToInt32(values["Wen"]);
}
protected void CancelEditing(CancelEventArgs e) {
e.Cancel = true;
Grid.CancelEdit();
}
public class GridDataItem {
public int ID { get; set; }
public int Mon { get; set; }
public int Tue { get; set; }
public int Wen { get; set; }
}
protected void Grid_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e) {
if (e.Column.FieldName == "Total") {
int tue = Convert.ToInt32(e.GetListSourceFieldValue("Tue"));
int mon = Convert.ToInt32(e.GetListSourceFieldValue("Mon"));
int wen = Convert.ToInt32(e.GetListSourceFieldValue("Wen"));
e.Value = mon + tue + wen;
}
}
protected void Grid_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e) {
if (e.DataColumn.FieldName == "Total")
e.Cell.Attributes.Add("onclick", "event.cancelBubble = true");
}
protected object GetSummaryValue(string fieldName) {
ASPxSummaryItem summaryItem = Grid.TotalSummary.First(i => i.Tag == fieldName + "_Sum");
return Grid.GetTotalSummaryValue(summaryItem);
}
}