Avoid using DataBinder.Eval for better performance

by Waqas 2/12/2008 6:43:00 PM

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>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET | Better Coding | Tips n Tricks

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading




Tags

© Copyright Beyond Web Logs.


Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in