1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
#endregion
|
23
|
|
|
24
|
|
using System;
|
25
|
|
using System.Collections;
|
26
|
|
using System.Reflection;
|
27
|
|
using System.Web.UI;
|
28
|
|
using System.Web.UI.WebControls;
|
29
|
|
using ShowX.Model;
|
30
|
|
using ShowX.Config;
|
31
|
|
|
32
|
|
namespace ShowX.Web.WebBuilders.ItemTemplates
|
33
|
|
{
|
34
|
|
|
35
|
|
|
36
|
|
|
37
|
|
public class CollectionItemTemplate : ITemplate {
|
38
|
|
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
PropertyInfo propertyInfo;
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
|
|
47
|
|
|
48
|
35
|
public CollectionItemTemplate(PropertyInfo pInfo)
|
49
|
|
{
|
50
|
35
|
this.propertyInfo = pInfo;
|
51
|
|
}
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
126
|
public void InstantiateIn(System.Web.UI.Control container)
|
59
|
|
{
|
60
|
126
|
System.Web.UI.WebControls.Label label = new System.Web.UI.WebControls.Label();
|
61
|
126
|
label.DataBinding += new EventHandler(TemplateControl_DataBinding);
|
62
|
126
|
container.Controls.Add(label);
|
63
|
126
|
label.Width = Unit.Percentage(100);
|
64
|
|
}
|
65
|
|
|
66
|
|
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
126
|
private void TemplateControl_DataBinding(object sender, System.EventArgs e)
|
73
|
|
{
|
74
|
126
|
ICollectionMap colmap = Configuration.Session.MappingHandler
|
75
|
|
.GetPropertyMap(propertyInfo) as ICollectionMap;
|
76
|
|
|
77
|
126
|
System.Web.UI.WebControls.Label label;
|
78
|
126
|
label = (System.Web.UI.WebControls.Label) sender;
|
79
|
126
|
DataGridItem container = (DataGridItem) label.NamingContainer;
|
80
|
|
|
81
|
126
|
ShowX.Web.WebControls.DataGrid dg = container.Parent.Parent
|
82
|
|
as ShowX.Web.WebControls.DataGrid;
|
83
|
|
|
84
|
126
|
label.ControlStyle.MergeWith(dg.ChildControlStyle);
|
85
|
|
|
86
|
126
|
ICollection values = DataBinder.Eval(container.DataItem,
|
87
|
|
propertyInfo.Name) as ICollection;
|
88
|
|
|
89
|
126
|
string strValue = string.Empty;
|
90
|
126
|
PropertyInfo pi = Configuration.Session.MappingHandler
|
91
|
|
.GetPK(colmap.ContainedType);
|
92
|
|
|
93
|
126
|
IIdentifierMap imap = Configuration.Session.MappingHandler
|
94
|
|
.GetPropertyMap(pi) as IIdentifierMap;
|
95
|
|
|
96
|
126
|
string idProp = (imap.SubstituteAttr == "")
|
97
|
|
? imap.Name : imap.SubstituteAttr;
|
98
|
|
|
99
|
126
|
foreach(object o in values) {
|
100
|
|
|
101
|
282
|
strValue += DataBinder.Eval(o,idProp) + ", ";
|
102
|
|
}
|
103
|
|
|
104
|
126
|
strValue = (strValue != string.Empty)
|
105
|
|
? strValue.Substring(0,strValue.Length-2)
|
106
|
|
: "(None)";
|
107
|
|
|
108
|
126
|
label.Text = strValue;
|
109
|
|
}
|
110
|
|
}
|
111
|
|
}
|
112
|
|
|