By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,717 Members | 2,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,717 IT Pros & Developers. It's quick & easy.

Bind ArrayList to DataList

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
"Bob Lehmann" <no****@dontbotherme.zzz> schrieb im Newsbeitrag
news:OZ**************@TK2MSFTNGP15.phx.gbl...
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

Nov 19 '05 #2

P: n/a
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
"Daniel Walzenbach" <da***************@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
"Bob Lehmann" <no****@dontbotherme.zzz> schrieb im Newsbeitrag
news:OZ**************@TK2MSFTNGP15.phx.gbl...
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


Nov 19 '05 #3

P: n/a
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/

"Bob Lehmann" <no****@dontbotherme.zzz> wrote in message
news:OZ**************@TK2MSFTNGP15.phx.gbl...
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

Jan 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.