473,513 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataBinding - DataList

I have a book which shows that I can do Databinding to a control like the
following:

<asp:Label ID="lblScorecardCmntCategory" Runat="server" text='<%#
Container.DataItem("Name") %>'></asp:Label>

When I run this I get a error about, somthing about it was expecting a
method, not a property. DataItem is a method, is it not? If I use the
longer "eval" form, it works just fine, but I do not understand what I am
doing wrong with this "version" of databinding.

Can you clear up my confustion?

Nov 18 '05 #1
4 1231
This would happen if the language you are using is C#. Replace
DataItem("Name") with DataItem["Name"] since DataItem is an array and is
referenced with square brackets in C#, instead of the curvy ones used in
Visual Basic.

Hope that helps,

--
--------------------------------------------------------
Peter Wright (www.petewright.org)
Author of ADO.NET Novice To Pro
From Apress. www.apress.com (and 10
other doorstops from Wrox)
"Jim Heavey" <Ji*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
I have a book which shows that I can do Databinding to a control like the
following:

<asp:Label ID="lblScorecardCmntCategory" Runat="server" text='<%#
Container.DataItem("Name") %>'></asp:Label>

When I run this I get a error about, somthing about it was expecting a
method, not a property. DataItem is a method, is it not? If I use the
longer "eval" form, it works just fine, but I do not understand what I am
doing wrong with this "version" of databinding.

Can you clear up my confustion?

Nov 18 '05 #2
Container.DataItem("Name") may look like a method, but it is really just an indexed property. Which as you found out, you can't put there :-)

Some reason you don't want to use DataBinder.Eval(Container.DataItem, "Name") ?
--Michael

"Jim Heavey" <Ji*******@nospam.com> wrote in message news:Xn*********************************@207.46.24 8.16...
I have a book which shows that I can do Databinding to a control like the
following:

<asp:Label ID="lblScorecardCmntCategory" Runat="server" text='<%#
Container.DataItem("Name") %>'></asp:Label>

When I run this I get a error about, somthing about it was expecting a
method, not a property. DataItem is a method, is it not? If I use the
longer "eval" form, it works just fine, but I do not understand what I am
doing wrong with this "version" of databinding.

Can you clear up my confustion?

Nov 18 '05 #3
I was told (read in a book) that it was less efficient.
Nov 18 '05 #4
When I use [] as you suggested, I get the following error (and yes, I was
using C#)..

Cannot apply indexing with [] to an expression of type 'object'
<%# Container.DataItem["CMT1"]%>

I know the book I was reading called it a method, so I just presumed that
it was.

So why does it not like this?
Nov 18 '05 #5

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

Similar topics

8
6149
by: pete | last post by:
Hi there, Can someone explain to me why I can't bind to an XmlDocument but I can bind to an XmlNodeList. It's my understanding that they both implement the IEnumerable interface which is...
2
2026
by: John | last post by:
Hi, heres a brief description of what I'm trying to do. I have a sql table named colors that looks like this: color_id color_name 1 blue 2 red 3......... and so...
1
1400
by: | last post by:
Hi, I posted a message a while ago about programatically databinding and got a response that did not make sense to me. Here's a brief description of what I want to do. If I create a regular...
1
2221
by: oafyuf | last post by:
Hi, I'm trying to learn ASP.NET by doing a pilot project: I have a DataGrid which contains a nested DataList. I want to iterate through the SQLDataReader for the DataGrid and populate each...
3
2258
by: Peter Morris [Droopy Eyes Software] | last post by:
Hi all When I bind to multiple records I use a DataList. This allows the web-designer to add code like <%#DataBinder.Eval(Container.DataItem, "Name")%> Whenever I want to retrieve a single...
6
2301
by: Nathan Sokalski | last post by:
I am using a DataSet as the DataSource of a DataList in my code. The SQL used to get the data from the database begins with: SELECT...
1
1387
by: Nathan Sokalski | last post by:
When I run my application, which uses databinding in a DataList, I recieve the following error: Server Error in '/' Application. ...
9
2293
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables...
0
1179
by: rb | last post by:
I'm struggling with (probably) basic things using SqlDataSource and DataList. Here's the problem: I need to read the resultset returned by SqlDataSource to perform actions related to visual...
2
1273
by: Sebastian | last post by:
Hi, I want to skin the templates of an asp:DataList. So I have to do data binding in the skin (I didn't find another comfortable way to do that). As soon there's a <%# ... %tag in the skin, VS...
0
7260
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
7384
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
7539
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...
1
7101
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
7525
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...
1
5089
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
4746
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
3234
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
456
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.