Length < 1))
{
propDesc = propDescCol[0];
}
CHAPTER 7 ?– SERVER CONTROL DATA B INDING 295
else //If dataMember is set, try to find it in the property collection
propDesc = propDescCol.Find(dataMember, true);
if (propDesc == null)
throw new Exception("ListSource missing DataMember");
object listitem = list[0];
//Get the value of the property (DataTable) of interest
object member = propDesc.GetValue(listitem);
if ((member == null) || !(member is IEnumerable))
throw new Exception("ListSource missing DataMember");
return (IEnumerable)member;
}
else
return (IEnumerable)list;
}
return null;
}
}
}
The end result is a PropertyDescriptor that allows us to dynamically retrieve the appropriate
data for binding. For the DataSet, this gives us a reference to a DataTable. We cast the
result to IEnumerable and return it to the control so that we can continue the data binding process.
PropertyDescriptor, PropertyDescriptorCollection, and IListSource are all members of
the System.ComponentModel namespace. This namespace plays a critical role in performing
dynamic lookups and enhancing the design-time experience of controls. We focus on the
design time support, including data binding design time support, in Chapter 11.
Pages:
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413