开发者

Arraylist as repeater datasource (how to access from .aspx)

I have an arraylist:

 Dim downloadsarray As New ArrayList
        downloadsarray.Add(iconlink) 
        downloadsarray.Add(imgpath) 
        downloadsarray.Add(filesize) 
        downloadsarray.Add(description) 

Which is the datasource of my repeater:

 DownloadsRepeater.DataSource = downloadsarray
    DownloadsRepeater.DataBind()

Please can you tell me how I output the items in the array to the .aspx page. I usually use (when using sqldatareader as datasource):

    <%#Container.DataItem("1stcolumnnamestring")%>
    <%#Container.DataItem("2ndcolumnnamestring")%>

But this does not work when using the arraylist as datasource.

Thanks.

ps... I know how to use <%#Container.DataItem%> to dump everything but I need to get at the items in the array individually, not have them all ditched out to the page i开发者_运维百科n one go. For example, item 1 contains a link, item 2 contains an image path, item 3 contains a description. I need to have them kick out in the correct order to build the link and icon correctly.


In your example, you should be able to do this:

 <%# Container.DataItem.ToString() %> 

Typically, when binding to a repeater, each data item holds the same type of data. In your example, each item is different - one is the link, one is the image path, etc. This is fine if all you want to display are those exact items (though I would then question whether you need a repeater to do the job).

If your intent is to show multiple links, you should create a class for each link and add instance of the class to your ArrayList:

class LinkThing {
  string link;
  string imagePath;
  etc... (do all the usual stuff with properties and constructors)
}

downloadsarray.Add(new LinkThing(link1, path1, size1, desc1));
downloadsarray.Add(new LinkThing(link2, path2, size2, desc2));

and in the aspx page:

 <%# ((LinkThing)Container.DataItem).link %> 
 <%# ((LinkThing)Container.DataItem).path %> 


Try and use Container.DataItem that should get you the individual elements of the array list.


Try

<%# Eval(Container.DataItem) #%> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜