Phi*_*hil 1 vb.net asp.net repeater datasource arraylist
我有一个arraylist:
Dim downloadsarray As New ArrayList
downloadsarray.Add(iconlink)
downloadsarray.Add(imgpath)
downloadsarray.Add(filesize)
downloadsarray.Add(description)
Run Code Online (Sandbox Code Playgroud)
哪个是我的中继器的数据源:
DownloadsRepeater.DataSource = downloadsarray
DownloadsRepeater.DataBind()
Run Code Online (Sandbox Code Playgroud)
请问您能告诉我如何将数组中的项输出到.aspx页面.我经常使用(当使用sqldatareader作为数据源时):
<%#Container.DataItem("1stcolumnnamestring")%>
<%#Container.DataItem("2ndcolumnnamestring")%>
Run Code Online (Sandbox Code Playgroud)
但是当使用arraylist作为数据源时,这不起作用.
谢谢.
ps ...我知道如何使用<%#Container.DataItem%>来转储所有内容,但我需要单独获取数组中的项目,而不是一次性将它们全部丢弃到页面中.例如,项目1包含链接,项目2包含图像路径,项目3包含描述.我需要以正确的顺序踢出它们才能正确构建链接和图标.
在您的示例中,您应该能够这样做:
<%# Container.DataItem.ToString() %>
Run Code Online (Sandbox Code Playgroud)
通常,当绑定到转发器时,每个数据项保持相同类型的数据.在你的例子中,每个项目都是不同的 - 一个是链接,一个是图像路径,等等.如果你想显示的只是那些确切的项目,那就没问题了(虽然我会问你是否需要一个转发器来完成这项工作).
如果您的目的是显示多个链接,则应为每个链接创建一个类,并将该类的实例添加到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));
Run Code Online (Sandbox Code Playgroud)
并在aspx页面中:
<%# ((LinkThing)Container.DataItem).link %>
<%# ((LinkThing)Container.DataItem).path %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7561 次 |
| 最近记录: |