Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ListDataHelper.cs « System.Web.Mobile.Util « System.Web.Mobile « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9279dc6fc0d23b58cb002c4e24fa9c44c08e19a8 (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
 * Project   : Mono
 * Namespace : System.Web.Mobile.Util
 * Class     : ListDataHelper
 * Author    : Gaurav Vaish
 *
 * Copyright : 2003 with Gaurav Vaish, and with
 *             Ximian Inc
 */

using System.Collections;
using System.Web.UI;
using System.Web.Mobile;
using System.Web.UI.MobileControls;

namespace System.Web.Mobile.Util
{
	internal class ListDataHelper
	{
		private object dataSource;
		private int    dataSourceCount = -1;
		private IEnumerable resolvedDataSrc;
		private MobileListItemCollection items;
		private string dataTextField;
		private string dataValueField;
		private bool   bindFromFields;

		private IListControl parent;
		private StateBag     parentViewState;

		public ListDataHelper(IListControl parent, StateBag parentViewState)
		{
			this.parent          = parent;
			this.parentViewState = parentViewState;
		}

		public string DataMember
		{
			get
			{
				object o = parentViewState["DataMember"];
				if(o != null)
					return (string)o;
				return String.Empty;
			}
			set
			{
				parentViewState["DataMember"] = value;
			}
		}

		public string DataTextField
		{
			get
			{
				object o = parentViewState["DataTextField"];
				if(o != null)
					return (string)o;
				return String.Empty;
			}
			set
			{
				parentViewState["DataTextField"] = value;
			}
		}

		public string DataValueField
		{
			get
			{
				object o = parentViewState["DataValueField"];
				if(o != null)
					return (string)o;
				return String.Empty;
			}
			set
			{
				parentViewState["DataValueField"] = value;
			}
		}

		public object DataSource
		{
			get
			{
				return this.dataSource;
			}
			set
			{
				this.dataSource = value;
			}
		}

		public int DataSourceCount
		{
			get
			{
				if(dataSourceCount == -1)
				{
					if(ResolvedDataSource != null)
					{
						if(ResolvedDataSource is ICollection)
							dataSourceCount = ((ICollection)ResolvedDataSource).Count;
					}
				}
				return dataSourceCount;
			}
		}

		public IEnumerable ResolvedDataSource
		{
			get
			{
				if(this.resolvedDataSrc == null)
				{
					resolvedDataSrc = DataSourceHelper.GetResolvedDataSource(DataSource, DataMember);
				}
				return resolvedDataSrc;
			}
		}

		public MobileListItemCollection Items
		{
			get
			{
				if(items == null)
				{
					items = new MobileListItemCollection();
					if(parent.TrackingViewState)
						((IStateManager)items).TrackViewState();
				}
				return items;
			}
		}

		public void AddItem(MobileListItem item)
		{
			Items.Add(item);
		}
		
		public MobileListItem CreateItem(object dataItem)
		{
			MobileListItem retVal;
			string itemText = null;
			string itemValue = null;
			if(bindFromFields)
			{
				if(this.dataTextField.Length > 0)
				{
					itemText = DataBinder.GetPropertyValue(dataItem,
					                        dataTextField, "{0}");
				}
				if(this.dataValueField.Length > 0)
				{
					itemValue = DataBinder.GetPropertyValue(dataItem,
					                         dataValueField, "{0}");
				}
			} else
			{
				itemText = dataItem.ToString();
			}
			retVal = new MobileListItem(dataItem, itemText, itemValue);
			if(dataItem != null)
			{
				parent.OnItemDataBind(new ListDataBindEventArgs(retVal, dataItem));
			}
			return retVal;
		}
	}
}