Bind ArrayList to DataList

B

Bob Lehmann

Hi,

I'm trying to bind an ArrayList to a DataList.

I get the error
DataBinder.Eval: 'System.String' does not contain a property with the name
Name.

I don't know what property of ArrayList I should be using instead of "Name"
in default.aspx.

Can someone point me in the right direction?

default.aspx.vb -
Dim di As New DirectoryInfo(Current.Server.MapPath("images/position"))
Dim FileList As FileInfo() = di.GetFiles()
Dim File As FileInfo
Dim ary As New ArrayList
For Each File In FileList
ary.Add(File.Name)
Next

ThumbList.DataSource = ary
ThumbList.DataBind()

default.aspx -
<asp:datalist id="ThumbList"
repeatdirection="Horizontal"
repeatcolumns="5"
gridlines="Both"
repeatlayout="Table"
itemstyle-cssclass="thumb"
runat="server">
<itemtemplate>
<img src='images/position/thumb/<%#DataBinder.Eval(Container,
"DataItem.Name")%>">' border='0'></a>
</itemtemplate>
</asp:datalist>

Thanks,
Bob Lehmann
 
D

Daniel Walzenbach

Bob,

without testing I'd assume that sth. like the following should work:

Dim di As New DirectoryInfo(Current.Server.MapPath("images/position"))
ThumbList.DataSource= di.GetFiles()
ThumbList.DataBind()

Does this help?

Best regards

Daniel Walzenbach
 
B

Bob Lehmann

Thanks.

I've tried that. However, the problem is that I need just the image name
from the ArrayList.

I've done this before, where each Name was a property of a class. In this
case, I don't need this kind of granularity, and just want to grab the value
from the ArrayList.

Bob Lehmann
 
D

Darren Kopp

Bob,

You are adding the string to the array. Name is not a member of the string
class (i know i just repeated the error). Change ary.Add(File.Name) to
ary.Add(File) and your bind should work fine.

For a more efficient approach, i believe that you can leave the
ary.Add(File.Name) but change the binding command to <img
src='images/position/thumb/<%#DataBinder.Eval(Container.DataItem)%>'>

Hope that helps,
Darren Kopp
http://blog.secudocs.com/
 
Joined
Jul 1, 2009
Messages
1
Reaction score
0
Bind ArrayList To DataList

Hi Friends

This code help u to solve ur problem
try this

DataBinder.Eval(Container,"DataItem")
insted of
DataBinder.Eval(Container,"DataItem.Name")
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top