LateBinding vs. OnItemDatabound binding revisited

W

Weston Weems

Ok, I first of all dont know if thats the proper verbage.. lemme explain...

Originally I was taught to handle databinding in a datagrid and such with
Databinder.Eval from the template.

Since then I've heard arguments for that and against.

What I've grown accustomed to is to just throw a generically named lable in
the template, then in onItemDataBound, do a e.Cells.FindControl("label") and
change properties appropriately (some times you have to do it this way)

I've heard the arguemnt against my methods, saying that asp.net allocates
memory etc for potentially hundreds of controls (on pages spitting out tons
of data).

Has anyone seen any speed/scalability benchmarks one way or another? I'd
prefer the findcontrol method and using e.Item.DataItem, to bind... as it
gives me a lot more power.

Thanks for the feedback (/me nudges asp.net team)
Weston Weems
 
K

Karl

If you are talking about simply dumping values, I think the DataBinder.Eval
is the best approach (although whoever claims to be a performance champion
using DataBinder.Eval needs to get his or her head checked -
((CustomClass)Container.DataItem).Property is the way to go). However, if
you are doing any processing, applying any presentation logic (or worse
business logic) this definitely belongs in OnItemDataBind.

For example, if you are simply doing a dump:

<itemTemplate>
<%# DataBinder.Eval(Container.DataItem, "MyValue") %>
</itemTemplate>

is the way to go, but if you need to hide/show that value, don't do:

<itemTemplate>
<asp:literal id="lit" runat="Server" visible='<%#
DataBinder.Eval(Container.DataItem, "blah") = 1%>'><%#
DataBinder.Eval(Container.DataItem, "MyValue") %></asp:literal>
</itemTemplate>

either do:

<itemTemplate>
<asp:literal id="lit" runat="Server"
visible='<%#GetVisibility(Container)%>'><%#
DataBinder.Eval(Container.DataItem, "MyValue") %></asp:literal>
</itemTemplate>


or better, use the ItemDataBound and FindControl("lit")


Karl
 

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top