473,395 Members | 1,956 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,395 software developers and data experts.

Container.DataItem or DataBinder.Eval

Hi,
Should I use
<%# Container.DataItem("Author")%>
or
<%# DataBinder.Eval(Container.DataItem,"Author") %>

What's the difference between both?
Thank You
Nov 19 '05 #1
2 8962
DataBinder.Eval uses reflection to get a value of a property of the
dataitem object. This is less performant than casting the dataitem
object to its actual type, and then access its property. The only
reason to use DataBinder.Eval is that the syntax may be/look simpler.

I always cast it to its actual type, which means it looks like this:
<%# ((MyObject)Container.DataItem).MyProperty %>
Or in case you are binding against a datatable, the dataitem is of the
the type datarowview:
<%# ((DataRowView)Container.DataItem)["MyField"] %>

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #2
Hi John:

The DataItem property returns a reference to an object, and
System.Object doesn't have an indexer defined. You'd have to cast the
DataItem return value to the proper type before the first expression
would compile.

DataBinder.Eval works because it will use reflection to dig out the
property with the name of "Author" dynamically. The second expression
would be the one to use in this case because it is the only one to
work.

There are some more details and alternatives here:
http://odetocode.com/Articles/278.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 28 Feb 2005 08:54:22 -0800, JohnZing
<jo**********@S.P.A.M.yahoo.com> wrote:
Hi,
Should I use
<%# Container.DataItem("Author")%>
or
<%# DataBinder.Eval(Container.DataItem,"Author") %>

What's the difference between both?
Thank You


Nov 19 '05 #3

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

Similar topics

2
by: az bij | last post by:
Hi, I have a dataset bound to a repeater and want to place some logic in my ascx file. I want to display an image link if and only if an image is available. I have tried without success...
0
by: Lauchlan M | last post by:
Hi In my aspx page HTML I have <a href='<%# DataBinder.Eval(Container.DataItem, "Name") %>'> <%# DataBinder.Eval(Container.DataItem, "Name") %> I am trying to create a hyperlink to...
2
by: Tom Lee | last post by:
Hi all, I have the following problem and I cannot solve it. If anyone can help me solve this problem. I use the following code <%#DataBinder.Eval(Container.DataItem, "Property")%> to display...
5
by: bg | last post by:
Hi! How do I check if "date" exists before using that code? I've built a RSSreader and sometimes there's a date in it and sometimes not. How can I check if it exists to avoid crash...
1
by: Charlie | last post by:
Hi: Is it possible to apply formatting to above statements which insert field values into HTML when binding to a datasource using Repeater control? For example, I would like to trim trailing...
3
by: Eric Newton | last post by:
Given databinding an array of System.Version types: Given that "SomeObject" type has a Version property: public class SomeObject { public Version Version { get; } public string Description {...
2
by: marcus.lecount | last post by:
Hi to anyone out there that is taking the time to read this. I'm new to ..net and any help given is appreciated. I am displaying a datalist on a page and I want to limit the length of the...
2
by: wubin_98 | last post by:
Hi All, Could any expert point out what is wrong in my code? I search around but couldn't found answer. It seems that I am the first person have this problem. Thanks in advanced I have a...
6
by: rn5a | last post by:
What's the difference between <%# DataBinder.Eval(Container.DataItem,"LastName") %> & <%# Container.DataItem("LastName") %> Thanks
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.