June 2009
M T W T F S S
« May   Jul »
1234567
891011121314
15161718192021
22232425262728
2930  

Use explicit casting instead of DataBinder.Eval

The DataBinder.Eval method uses .NET reflection to evaluate the arguments that are passed in and to return the results. Consider limiting the use of DataBinder.Eval during data binding operations in order to improve ASP.NET page performance.

Consider the following ItemTemplate element within a Repeater control using DataBinder.Eval:

<ItemTemplate>

<tr>

<td><%# DataBinder.Eval(Container.DataItem, “field1″) %></td>

<td><%# DataBinder.Eval(Container.DataItem, “field2″) %></td>

</tr>

</ItemTemplate>

Using explicit casting offers better performance by avoiding the cost of .NET reflection. Cast the Container.DataItem as a DataRowView:

<ItemTemplate>

<tr>

<td><%# ((DataRowView)Container.DataItem)["field1"] %></td>

<td><%# ((DataRowView)Container.DataItem)["field2"] %></td>

</tr>

</ItemTemplate>

2/12/2008

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>