29
09 Mar.
如何将 ArrayList, Dictionary 绑定到 Repeater?
最后更新: 2009/03/29 | 评论: 0 | 关键词: ArrayList Dictionary Repeater 绑定
看 MSDN 上讲,可以作为数据绑定控件的数据源对象需要继承并实现 IEnumerable 或 IListSource 接口。
而 Dictionary 字典类很明显是继承并实现了 IEnumerable 接口的,那么如何将一个 Dictionary 对象绑定到 Repeater 等控件呢?
- Partial Class Repeater_Dictionary_Test
- Inherits System.Web.UI.Page
- Private SourceDictionary As New Dictionary(Of String, String)()
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- SourceDictionary.Add("木炭", "http://www.woodcoal.cn/")
- SourceDictionary.Add("无尘", "http://www.ekv.cn/")
- SourceDictionary.Add("可乐·婷", "http://www.colastop.cn/")
- SourceDictionary.Add("牛档", "http://www.niudown.com/")
- showRepeater.DataSource = SourceDictionary
- showRepeater.DataBind()
- End Sub
- End Class
而在前台的使用则是通过数据绑定,如下所示(片段)
- <form runat="server">
- <asp:Repeater id="List" runat="server">
- <HeaderTemplate>
- <table border="1" width="100%">
- <tr>
- <th>站长</th>
- <th>网站</th>
- </tr>
- </HeaderTemplate>
- <ItemTemplate>
- <tr>
- <td><%#Eval("key")%></td>
- <td><%#Eval("value")%></td>
- </tr>
- </ItemTemplate>
- <FooterTemplate>
- </table>
- </FooterTemplate>
- </asp:Repeater>
- </form>
如果使用的是 ArrayList 等类时,绑定时,直接用 <%# Container.DataItem%> 就可以了。
· 本文由 木炭 发布在《激情燃烧的木炭》 上,原文地址为:http://www.woodcoal.cn/technology/asp/2009329-23140-518.html(转载请保留本信息、全文内容和链接)
关于本文
- 作者:
- 来源:
- 时间:2009/03/29
- 关键词:ArrayList Dictionary Repeater 绑定
- 栏 目:ASP/.Net
- 上一篇:关于《SiteServer CMS 中 ajaxProxy 改进》升级到 SiteServer CMS 3.3 Beta 3 表单提交编码出错的问题
- 下一篇:.Net 中兼容 ASP 版的 MD5 算法 (C# 版本)
发表评论