SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 402 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"


The DummyDataSource Class and Postback
If CreateControlHierarchy is not in the midst of a DataBind, it needs to determine whether or
not it is in a postback environment. We can check this by looking for the ItemCount variable in
ViewState. If it is present, we create a DummyDataSource object that is appropriately named,
because it serves as a placeholder to rehydrate the control state that was originally rendered
and sent back to the web server via postback. Listing 7-4 provides the class source code for
DummyDataSource.
Listing 7-4. The DummyDataSource Class File
using System;
using System.Collections;
using System.ComponentModel;
296 CHAPTER 7 ?–  SE RVER CONTROL DATA B INDING
namespace ControlsBook2Lib.Ch07
{
internal sealed class DummyDataSource : ICollection
{
public DummyDataSource(int dataItemCount)
{
this.Count = dataItemCount;
}
public int Count { get; set; }
public bool IsReadOnly
{
get
{
return false;
}
}
public bool IsSynchronized
{
get
{
return false;
}
}
public object SyncRoot
{
get
{
return this;
}
}
public void CopyTo(Array array, int index)
{
for (IEnumerator e = this.GetEnumerator(); e.MoveNext();)
array.SetValue(e.Current, index++);
}
public IEnumerator GetEnumerator()
{
return new DummyDataSourceEnumerator(Count);
}
CHAPTER 7 ?–  SERVER CONTROL DATA B INDING 297
private class DummyDataSourceEnumerator : IEnumerator
{
private int count;
private int index;
public DummyDataSourceEnumerator(int count)
{
this.


Pages:
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6