473,503 Members | 1,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LateBinding vs. OnItemDatabound binding revisited

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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Weston Weems" <wweems@nospamdamnit_gmail.com> wrote in message
news:10*************@corp.supernews.com...
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

Nov 18 '05 #2
"Real World ASP.NET Best Practices" did some benchmarking.

http://tinyurl.com/3kmhe

Greg

"Weston Weems" <wweems@nospamdamnit_gmail.com> wrote in message
news:10*************@corp.supernews.com...
Has anyone seen any speed/scalability benchmarks one way or another?

Nov 18 '05 #3

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

Similar topics

4
1498
by: Weston Weems | last post by:
I currently populate my datagrids manually from a codebehind and use webcontrols within the template columns (for check boxes and viewing pleasure eg labels) For performance and scalability......
2
1993
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...
1
1503
by: rmccinc | last post by:
OK, I am running into some issues that I cant figure out a work-around. I am not going to post code cause I figured out WHY my issue is happening: -I have a datagrid, and a button that fires a...
3
961
by: Spondishy | last post by:
Hi, I have a datalist control, and in each row I have a label and a hyperlink control. The label is bound to an id field in the db. What I'm trying to do is hide the hyperlink if the id is a...
1
1139
by: Mikeon | last post by:
Hello! I have a problem customizing the databound controls using the OnItemDataBound event. The code below is an example of what I'm trying to do. I have a datasource and basing on the data I...
14
8639
by: TS | last post by:
I have this custom data list control and i override the onItemDatabound event. After upgrading to vs 2005, this event is not always getting called, though it does at other times. No changes were...
4
1692
by: Hakan ÖRNEK | last post by:
Hi, I have two dll's like First.dll and Second.dll compiled by vb.net, a object in first.dll and, b object in Second.dll. I need hold cross referances; a.breferance=b and b.areferance=a I...
0
1649
by: Brian Lowe | last post by:
I'm in a web page and I have hierarchical data so I'm using 2 nested DataList controls. DataList1 is using a data source with rows of , , and where MoreData is a list. DataList1 has an...
2
1795
by: RN1 | last post by:
Consider the following code: ------------------------------ <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then 'binding data from...
0
7201
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
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
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
5578
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,...
1
5011
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...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.