Other
Defensive Datasource
Some ASP.NET controls, such as DataGrid
, expect all the elements of the DataSource
collection to have the same type when you call the control's DataBind
method. Sometimes, the restriction seems to be a bit looser: if the collection is not an ITypedList
, then for each property of the first element in the collection, the control will expect to find that property on every element in the collection. Either way, it's inconvenient, and it happens even if you have AutoGenerateColumns = false
.
Consider the case when you want to display the properties defined in a superclass for a set of subclass instances. Some people call this "polymorphic databinding" because the elements of the collection are heterogeneous but derived from a common supertype (aka BaseType
). If you try to simply bind an IEnumerable
container to your DataGrid
, you will g
asp.net
.net
DotNet
datasource
Heterogeneous
polymorphic
databind
No comment