This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.aspx.cs
70 lines (62 loc) · 2.59 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
using System;
using System.IO;
using System.Web.UI;
using DevExpress.Utils.Serializing.Helpers;
namespace ASPxPivotGrid_CustomObjectConverter {
public partial class _Default : Page {
protected override void OnInit(EventArgs e) {
base.OnInit(e);
ASPxPivotGrid1.DataSource = DataHelper.GetData();
ASPxPivotGrid1.OptionsData.CustomObjectConverter = new CustomObjectConverter();
}
// Handles the Save button's Click event to save pivot grid data to a stream
// (requires data source serialization).
protected void ASPxButton1_Click(object sender, EventArgs e) {
Session["Layout"] = ASPxPivotGrid1.SaveLayoutToString();
}
// Handles the Load button's Click event to load pivot grid data from a stream
// (requires stream content deserialization).
protected void ASPxButton2_Click(object sender, EventArgs e) {
string layout = (string)Session["Layout"];
if (layout == null) {
return;
}
ASPxPivotGrid1.LoadLayoutFromString(layout);
}
}
// Implements a custom serializer.
public class CustomObjectConverter : ICustomObjectConverter {
// Returns a value, indicating whether objects of the specified type
// can be serialized/deserialized.
public bool CanConvert(Type type) {
return type == typeof(Employee);
}
// Deserializes objects of the specified type.
public object FromString(Type type, string str) {
if (type != typeof(Employee))
return null;
string[] array = str.Split('#');
if (array.Length >= 3)
return new Employee(array[0], array[1], int.Parse(array[2]));
else if (array.Length == 2)
return new Employee(array[0], array[1], 0);
else if (array.Length == 1)
return new Employee(array[0], string.Empty, 0);
else
return new Employee(string.Empty, string.Empty, 0);
}
// Serializes objects of the specified type.
public string ToString(Type type, object obj) {
if (type != typeof(Employee))
return string.Empty;
Employee value = obj as Employee;
return value.FirstName + '#' + value.LastName + '#' + value.Age;
}
// Returns the type by its full name.
public Type GetType(string typeName) {
if (typeName != typeof(Employee).FullName)
return null;
return typeof(Employee);
}
}
}