Hi. I have a straight-forward "OleDbDataReader" object that's been returned
from a SELECT statement against an MS Access file. I've tested the DataReader
and it has data and is set up right.

Now I'm trying to use the ASP.NET Repeater WebControl to display the data. I
read the documentation and it says that in the <ItemTemplate> section of the
Repeater, I can use the following notation:

<ItemTemplate>
<%# Container.DataItem("LastName") %>
</ItemTemplate>

BUT when I do this, I get the following error:

"CS0118: 'System.Web.UI.WebControls.RepeaterItem.DataItem' denotes a
'property' where a 'method' was expected"

What does this mean? If I replace this notation with:
<%# DataBinder.Eval(Container.DataItem, "ID") %>

it works, but I've read that that's FAR less efficient. What am I doing wrong?

Thanks.

Alex

Re: Error using Container.DataItem("<field>") in Repeater ItemTemplate by Joyjit

Joyjit
Sun Nov 14 23:23:56 CST 2004

Hi,

Container is the object reference against which the entire expression is
evaluated. Dataitem is the property of the Container object to which the
Listitem is bound. But the <ItemTemplate> tab for the listitem is evaluated
each time for the number of rows, so a simple property can't be bound to a
control expecting complex datasource.

And yes, DataBinder.Eval is slow becauses it uses reflection at runtime to
format and bind the data.

HTH
Regards
Joyjit

"Alex Maghen" <AlexMaghen@discussions.microsoft.com> wrote in message
news:67AE5D83-A2E0-438E-BB97-21903513F379@microsoft.com...
> Hi. I have a straight-forward "OleDbDataReader" object that's been
returned
> from a SELECT statement against an MS Access file. I've tested the
DataReader
> and it has data and is set up right.
>
> Now I'm trying to use the ASP.NET Repeater WebControl to display the data.
I
> read the documentation and it says that in the <ItemTemplate> section of
the
> Repeater, I can use the following notation:
>
> <ItemTemplate>
> <%# Container.DataItem("LastName") %>
> </ItemTemplate>
>
> BUT when I do this, I get the following error:
>
> "CS0118: 'System.Web.UI.WebControls.RepeaterItem.DataItem' denotes a
> 'property' where a 'method' was expected"
>
> What does this mean? If I replace this notation with:
> <%# DataBinder.Eval(Container.DataItem, "ID") %>
>
> it works, but I've read that that's FAR less efficient. What am I doing
wrong?
>
> Thanks.
>
> Alex



Re: Error using Container.DataItem("<field>") in Repeater ItemTemplate by v

v
Sun Nov 14 23:25:15 CST 2004

did you try explicitly casting using DataRowView ? i.e.,
((DataRowView)Container.DataItem)["LastName"]

Regards,
venkat.Murthy

"Alex Maghen" <AlexMaghen@discussions.microsoft.com> wrote in message
news:67AE5D83-A2E0-438E-BB97-21903513F379@microsoft.com...
> Hi. I have a straight-forward "OleDbDataReader" object that's been
> returned
> from a SELECT statement against an MS Access file. I've tested the
> DataReader
> and it has data and is set up right.
>
> Now I'm trying to use the ASP.NET Repeater WebControl to display the data.
> I
> read the documentation and it says that in the <ItemTemplate> section of
> the
> Repeater, I can use the following notation:
>
> <ItemTemplate>
> <%# Container.DataItem("LastName") %>
> </ItemTemplate>
>
> BUT when I do this, I get the following error:
>
> "CS0118: 'System.Web.UI.WebControls.RepeaterItem.DataItem' denotes a
> 'property' where a 'method' was expected"
>
> What does this mean? If I replace this notation with:
> <%# DataBinder.Eval(Container.DataItem, "ID") %>
>
> it works, but I've read that that's FAR less efficient. What am I doing
> wrong?
>
> Thanks.
>
> Alex