DataBinding - DataList

J

Jim Heavey

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?
 
P

Pete Wright

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,



--
 
R

Raterus

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
 
J

Jim Heavey

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top