473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

What is most efficient? OnItemDataBound or using a function

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
Nov 18 '05 #1
4 1802
Hi,

I don't think there is much difference with these approaches, at least not
significant. The performance hit with databinding comes when you use
DataBInder.Eval in databinding expressions because it would cause
latebinding to be used and if you pass DataItem to custom function or use
built-in ItemDataBound you are all the-time running strongly-typed code
which can be optimized by the runtime.

You can think that ItemDataBound is called in any case. If you add your
custom function, it would be one slight step more to run, but as I said, the
difference is 0 in practise. All code is compiled and if you use it as typed
as possible, e.g avoid late-binding there's not much to think with it.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


"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

Nov 18 '05 #2
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

Nov 18 '05 #3
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" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:ev**************@TK2MSFTNGP11.phx.gbl...
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


Nov 18 '05 #4
I would think <%# ((DataRowView) Container.DataItem) ["OrderID"]%> would
preform the same as using the generic method for the entire datarow, since
they both avoid late binding.

The generic method I showed has some benefites in that you can refer to the
other columns from within the same function.

It doesn't really say why the event handler is faster (at least I am not
seeing it right now). But it does mention having to use FindControl in the
event handler method, which could be a bottleneck. (IMO)

Greg
"Anders" <no***@damnspam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:ev**************@TK2MSFTNGP11.phx.gbl...
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
>
>



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
3
by: Brent Minder | last post by:
What is the most efficient way to code asp.net pages when you break your page up into user controls? For example: If you have a page with a header (control .ascx), body, and footer (control...
2
by: Girish | last post by:
Hello all, Im wondering why my OnItemDataBound gets fired twice here. I got this sample code from somewhere online.. and when I put a break point in the method... it hits the method twice for...
20
by: athar.mirchi | last post by:
..plz define it.
10
by: timor.super | last post by:
Hi all, Imagine I've an array of int : int anArray = new int; I want to extract all the integer that are superior to 500 I can do :
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.