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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
//------------------------------------------------------------------------------
// <copyright file="ListDataHelper.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Collections;
using System.Diagnostics;
namespace System.Web.UI.MobileControls
{
/*
* List Data Helper class.
*
* Copyright (c) 2000 Microsoft Corporation
*/
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal sealed class ListDataHelper
{
private IListControl _parent;
private StateBag _parentViewState;
private MobileListItemCollection _items;
private Object _dataSource;
private IEnumerable _resolvedDataSource;
private int _dataSourceCount = -1;
private String _dataTextField;
private String _dataValueField;
private bool _bindFromFields;
internal /*public*/ ListDataHelper(IListControl parent, StateBag parentViewState)
{
_parent = parent;
_parentViewState = parentViewState;
}
internal /*public*/ MobileListItemCollection Items
{
get
{
if (_items == null)
{
_items = new MobileListItemCollection();
if (_parent.TrackingViewState)
{
((IStateManager)_items).TrackViewState();
}
}
return _items;
}
}
internal /*public*/ bool HasItems()
{
return _items != null;
}
internal /*public*/ Object DataSource
{
get
{
return _dataSource;
}
set
{
_dataSource = value;
_resolvedDataSource = null;
}
}
internal /*public*/ String DataMember
{
get
{
String s = (String)_parentViewState["DataMember"];
return s == null ? String.Empty : s;
}
set
{
_parentViewState["DataMember"] = value;
}
}
internal /*public*/ String DataTextField
{
get
{
String s = (String)_parentViewState["DataTextField"];
return (s != null) ? s : String.Empty;
}
set
{
_parentViewState["DataTextField"] = value;
}
}
internal /*public*/ String DataValueField
{
get
{
String s = (String)_parentViewState["DataValueField"];
return (s != null) ? s : String.Empty;
}
set
{
_parentViewState["DataValueField"] = value;
}
}
internal /*public*/ IEnumerable ResolvedDataSource
{
get
{
if (_resolvedDataSource == null)
{
_resolvedDataSource =
DataSourceHelper.GetResolvedDataSource(DataSource, DataMember);
}
return _resolvedDataSource;
}
}
/*
internal int DataSourceCount
{
get
{
if (_dataSourceCount == -1)
{
IEnumerable dataSource = ResolvedDataSource;
if (dataSource != null)
{
ICollection collection = dataSource as ICollection;
if (collection != null)
{
_dataSourceCount = collection.Count;
}
else
{
int count = 0;
IEnumerator enumerator = dataSource.GetEnumerator();
while (enumerator.MoveNext())
{
count++;
}
_dataSourceCount = count;
}
}
else
{
_dataSourceCount = 0;
}
}
return _dataSourceCount;
}
}
*/
internal /*public*/ void CreateItems(IEnumerable dataSource)
{
Debug.Assert (dataSource != null);
Items.Clear();
_dataTextField = DataTextField;
_dataValueField = DataValueField;
_bindFromFields = (_dataTextField.Length > 0) || (_dataValueField.Length > 0);
foreach (Object dataItem in dataSource)
{
MobileListItem listItem = CreateItem(dataItem);
if (listItem != null)
{
AddItem(listItem);
}
}
_dataSourceCount = Items.Count;
}
private MobileListItem CreateItem(Object dataItem)
{
MobileListItem listItem = null;
String textField = null;
String valueField = null;
if (_bindFromFields)
{
if (_dataTextField.Length > 0)
{
textField = DataBinder.GetPropertyValue(dataItem, _dataTextField, "{0}");
}
if (_dataValueField.Length > 0)
{
valueField = DataBinder.GetPropertyValue(dataItem, _dataValueField, "{0}");
}
}
else
{
textField = dataItem.ToString();
}
listItem = new MobileListItem(dataItem, textField, valueField);
// Use delegated data binding, if specified.
if (dataItem != null)
{
_parent.OnItemDataBind(new ListDataBindEventArgs(listItem, dataItem));
}
return listItem;
}
internal /*public*/ void AddItem(MobileListItem item)
{
MobileListItemCollection items = Items;
items.Add(item);
}
}
}
|