Need help with Repeater data binding question...

  • Thread starter Thread starter Milsnips
  • Start date Start date
M

Milsnips

hi there,

i have a page with a repeater that is populated with my function called
GetList, that returns an arraylist of my custom object, lets say its called
Products{ProductID, Description, Price}

Now, if the datasource of the repeater is something like DataSet or
SQLDataReader and i'm returning the records, not the arraylist of "Products"
objects, in the aspx code i can use <%#
Container.DataItem("ProductID")%>....

How can i show the data in this forn <%# Container.Dataitem.....etc.%> so i
can read the Property value, eg. Products.Description, or Products.Price??

thanks for anyone's help.
Paul
 
Well, i'm not sure why people are still using ArrayList for
datasources, but you would be having a much easier time if you used
something typesafe, like Collection<Product> or List<Product>

The reason the databinder evaluations are failing is because it has no
idea what kind of type is stored in the arraylist, since theyre only
stored as objects.
 
The databinding expressions are pretty smart..

you can actually do:

<%# DataBinder.Eval(Container.DataItem "Description") %> and it'll work (or
the short-hand Eval in 2.0)

you could always cast it directly:

<%# ((Product)Container.DataItem).Description %>

Karl
 
hi there,

i tried them both, with no success..
i used this line: <%# DataBinder.Eval(Container.DataItem, "Comment") %>

my error returned is: Exception Details: System.Web.HttpException:
DataBinder.Eval: 'Kolesino2006.PhotoAlbum+Photo' does not contain a property
with the name CommentID.

my class is called Photo, and it has readonly propertyies CommentID,
Comment, and so on.

thanks,
Paul


"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
 
Is it a property or a field???


public string CommentID

or

public string CommentId
{
get {return _commentId;}
}


?

The 1st won't work...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Milsnips said:
hi there,

i tried them both, with no success..
i used this line: <%# DataBinder.Eval(Container.DataItem, "Comment") %>

my error returned is: Exception Details: System.Web.HttpException:
DataBinder.Eval: 'Kolesino2006.PhotoAlbum+Photo' does not contain a
property with the name CommentID.

my class is called Photo, and it has readonly propertyies CommentID,
Comment, and so on.

thanks,
Paul


"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
 
so photo is an inner class to PhotoAlbum?

when you say readonly property, do mean a property with only a getter
or are you attempting to bind directly to a public field?
 
Hi,

yes it is a declared property, as such:
Private _comment As String

ReadOnly Property Comment() As String
Get
Return _comment
End Get
End Property

And to the other question from "kferron", yes its a class within another, so
"PhotoAlbum.Photo"

Also, if i just do <%# Container.DataItem%> it returns me
"mynamespace.PhotoAlbum+Photo" so it can see the object in the dataitem i
guess.

regards,
Paul


"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
 
Back
Top