From "Real World ASP.NET Best Practices" (ch.5)
Basically there are three options avaialable:
1.inline format expressions (ex. using DataBinder.Eval)
2.event handlers (ex. using OnItemDataBound)
3.member methods (ex. your method/funciton call)
Their conclusions (whith performance tests to back it up): members methods
perform much better than event handlers and just a fast as inline format
expressions.
They go on to give an example that is quite interesting: (Rather than a
member method for each dataitem, they make one generic one for the entire
datarow)
In aspx page code like
<td><%#ShowData(Container.DataItem, "OrderID")%></td>
<td><%#ShowData(Container.DataItem, "CompanyName")%></td>
<td><%#ShowData(Container.DataItem, "OrderDate")%></td>
In codebehind:
Protected Function ShowData(data as object, ColumnName as string) as string
Dim inputdata as DataRowView = CType(data, DataRowView)
Select Case ColumnName
Case "OrderID"
return inputData("OrderID").Tostring
Case "CompanyName"
return inputData("Compyname").Tostring
Case "OrderDate"
return (format inputData("OrderDate") however you want here)
Case Else
return ""
End Select
End Function
HTH,
Greg
"Anders" <no***@damnspam.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Hi, I was wondering what is most efficient of the two.
Is it more efficient to add server controls within the Itemtemplate and
use
OnItemDataBound to manipulate and databind the servercontrols.
Or is better to send the DataItems via. a method/function from within the
Itemtemplate (<%# call function %>)
Id love to hear your thoughts.
Anders