Home >

Avoid using DataBinder.Eval for better performance

8. March 2011

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

Consider the following ItemTemplate element DataBinder.Eval.

<ItemTemplate>

 <tr>

  <td><%# DataBinder.Eval(Continer.DataItem, "fieldname1") %></td>

  <td><%# DataBinder.Eval(Continer.DataItem, "fieldname2") %></td>

</tr>

</ItemTemplate>

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

<ItemTemplate>

 <tr>

  <td><%# ((DataRowView)Continer.DataItem)["fieldname1"] %></td>

  <td><%# ((DataRowView)Continer.DataItem)["fieldname2"] %></td>

 </tr>

</ItemTemplate>

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading