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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
//------------------------------------------------------------------------------
// <copyright file="ObjectListField.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Security.Permissions;
namespace System.Web.UI.MobileControls
{
/*
* Object List Field class.
*
* Copyright (c) 2000 Microsoft Corporation
*/
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField"]/*' />
[
PersistName("Field")
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[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.")]
public sealed class ObjectListField : IStateManager
{
private StateBag _stateBag = new StateBag();
private bool _marked;
private PropertyDescriptor _dataFieldDescriptor;
private ObjectList _owner;
private bool _selfReference = false;
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.Name"]/*' />
[
DefaultValue("")
]
public String Name
{
get
{
String s = (String)ViewState["Name"];
return (s == null) ? String.Empty : s;
}
set
{
ViewState["Name"] = value;
}
}
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.DataField"]/*' />
[
DefaultValue("")
]
public String DataField
{
get
{
String s = (String)ViewState["DataField"];
return (s == null) ? String.Empty : s;
}
set
{
ViewState["DataField"] = value;
NotifyOwnerChange();
}
}
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.DataFormatString"]/*' />
[
DefaultValue("")
]
public String DataFormatString
{
get
{
String s = (String)ViewState["DataFormatString"];
return (s == null) ? String.Empty : s;
}
set
{
ViewState["DataFormatString"] = value;
NotifyOwnerChange();
}
}
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.Title"]/*' />
[
DefaultValue("")
]
public String Title
{
get
{
String s = (String)ViewState["Title"];
return (s == null) ? String.Empty : s;
}
set
{
ViewState["Title"] = value;
}
}
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.Visible"]/*' />
[
DefaultValue(true)
]
public bool Visible
{
get
{
Object b = ViewState["Visible"];
return (b == null) ? true : (bool)b;
}
set
{
ViewState["Visible"] = value;
}
}
internal bool SelfReference
{
get
{
return _selfReference;
}
set
{
_selfReference = value;
}
}
internal String UniqueID
{
get
{
Object o = ViewState["Name"];
if (o != null)
{
return (String)o;
}
return (String)ViewState["DataField"];
}
}
private void NotifyOwnerChange()
{
// Only called if databinding behavior of the field changes.
if (_owner != null)
{
_owner.OnFieldChanged(false); // fieldAddedOrRemoved = false;
}
}
private StateBag ViewState
{
get
{
return _stateBag;
}
}
internal void SetOwner(ObjectList owner) {
_owner = owner;
}
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.DataBindItem"]/*' />
public void DataBindItem(int fieldIndex, ObjectListItem item)
{
Object dataItem = item.DataItem;
if (dataItem == null)
{
return;
}
if (!SelfReference)
{
String dataField = DataField;
if (dataField.Length == 0)
{
return;
}
_dataFieldDescriptor = TypeDescriptor.GetProperties(dataItem).Find(dataField, true);
if (_dataFieldDescriptor == null && !_owner.MobilePage.DesignMode)
{
throw new Exception(
SR.GetString(SR.ObjectListField_DataFieldNotFound, dataField));
}
}
Object data;
if (_dataFieldDescriptor != null)
{
data = _dataFieldDescriptor.GetValue(dataItem);
}
// Use fake databound text if the datasource is not accessible at designtime.
else if (_owner.MobilePage.DesignMode)
{
data = SR.GetString(SR.ObjectListField_DataBoundText);
}
else
{
Debug.Assert(SelfReference, "Shouldn't get this far if !SelfReference");
data = dataItem;
}
String dataText;
if ((data != null) && (data != System.DBNull.Value))
{
String dataFormatString = DataFormatString;
if (dataFormatString.Length > 0)
{
dataText = String.Format(CultureInfo.InvariantCulture, dataFormatString, data);
}
else
{
dataText = data.ToString();
}
}
else
{
dataText = String.Empty;
}
item[fieldIndex] = dataText;
}
/////////////////////////////////////////////////////////////////////////
// STATE MANAGEMENT
/////////////////////////////////////////////////////////////////////////
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.IStateManager.IsTrackingViewState"]/*' />
/// <internalonly/>
bool IStateManager.IsTrackingViewState
{
get
{
return _marked;
}
}
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.IStateManager.TrackViewState"]/*' />
/// <internalonly/>
void IStateManager.TrackViewState()
{
_marked = true;
((IStateManager)ViewState).TrackViewState();
}
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.IStateManager.LoadViewState"]/*' />
/// <internalonly/>
void IStateManager.LoadViewState(Object state)
{
if (state != null)
{
((IStateManager)ViewState).LoadViewState(state);
}
}
/// <include file='doc\ObjectListField.uex' path='docs/doc[@for="ObjectListField.IStateManager.SaveViewState"]/*' />
/// <internalonly/>
Object IStateManager.SaveViewState()
{
return ((IStateManager)ViewState).SaveViewState();
}
internal void SetDirty()
{
// VSWHIDBEY 236464. The bag needs to be set dirty not individual items.
_stateBag.SetDirty(true);
/*
foreach (StateItem item in _stateBag.Values)
{
item.IsDirty = true;
}
*/
}
internal void ClearViewState()
{
ViewState.Clear();
}
}
}
|