二,执行效率
从“一”讲述的低层实现。我们很容易来排序下面数据绑定表达式的执行效率
<%#Container.DataItem%>
<%#GetDataItem()%>
<%#Ev
<%#DataBinder.Ev
<%#((DataRowView)Container.DataItem)["字段名"] %>
<%#((Type)Container.DataItem).成员 %>
<%#((Type)GetDataItem()).成员 %>
1,效率最高应该是:
<%#((Type)Container.DataItem).成员 %>
<%#Container.DataItem%>
<%#((DataRowView)Container.DataItem)["字段名"] %>
2,效率排第二的是:
<%#((Type)GetDataItem()).成员 %>
<%#GetDataItem()%>
3,效率最低的是:
<%#Ev
<%#DataBinder.Ev
其实按上面的排序有失公允,原因是这七种数据表达绑定形式运用的场合不是完全相同的。
使用场合大概如下:
1,
|<%#Ev
<%#DataBinder.Ev
它们的使用场合最广,数据源可以为与数据库有关的DataSet,DataTable,DataView.也可以为普通集合(例如:数组,ArrayList,HashTable等)和泛行集合(例如:List<T>,Dictionary<Tkey,Tvalue>等)。
注:它们2个永远可以相互替换,至少目前是这样,凡是可以用Ev
2,
<%#((DataRowView)Container.DataItem)["字段名"] %>
它只能使用在数据源为与数据库有关的Dataset,DatTable,DataView.这些数据源都实现了IListSource接口。其实从低层实现本质上来看,它和<%#((Type)Container.DataItem)。成员 %>类似。
3,
<%#Container.DataItem%>
<%#GetDataItem()%>
<%#((Type)Container.DataItem).成员 %>
<%#((Type)GetDataItem()).成员 %>
这几种形式估计大家最不常用。它们一般只使用与普通集合(例如:数组,ArrayList,HashTable)和泛行集合(例如:List<T>,Dictionary<Tkey,Tvalue>)。其实本质上就是实现了IList,ICollection,IEnumerable,IDictionary等以及这些接口对应的泛行接口的集合。IList接口和IDictionary接口的区别是,一个只有值,而另一个是键/值对,对应泛行形式也是这样。而Array就对用List<T>,而HashTable就对应Dictionary<Tkey,Tvalue>.
评论