What I can conclude from both your replies is to avoid latebinding and use
methods or event handlers. Also still, making one generic method for the
entire datarow should perform better than strongly define each dataitem
like
this: <%# ((DataRowView) Container.DataItem) ["OrderID"]%>
Greg does the book say anything about why event handlers are slower?
Greg Burns said:
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