DataList绑定数据到泛型类(Dictionary)
2011-05-13 15:23
288 查看
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections.Generic; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Dictionary<string, A> d = new Dictionary<string, A>(); d.Add("aa", new A("1", "xx")); d.Add("bb", new A("2", "yy")); d.Add("cc", new A("3", "zz")); DataList1.DataSource = d; DataList1.DataBind(); } } } public class A { private string m_PKID; private string m_Type; public string PKID { get { return m_PKID; } set { m_PKID = value; } } public string Type { get { return m_Type; } set { m_Type = value; } } public A() { } public A(string pkid, string type) { this.m_PKID = pkid; this.m_Type = type; } }
<asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound"> <ItemTemplate> <%#( (System.Collections.Generic.KeyValuePair<string, A>)(Container.DataItem)).Key %> <%#( ((System.Collections.Generic.KeyValuePair<string, A>)(Container.DataItem)).Value as A).PKID %> <%#( ((System.Collections.Generic.KeyValuePair<string, A>)(Container.DataItem)).Value as A).Type %> </ItemTemplate> </asp:DataList>
(本文转载至:http://blog.csdn.net/amandag/archive/2008/07/05/2613328.aspx#)
相关文章推荐
- DataList绑定数据到泛型类(Dictionary) 【转】
- DataList绑定数据到泛型类(Dictionary)
- DataList绑定数据到泛型类(Dictionary)
- DataList绑定数据到泛型类(Dictionary)
- DataList绑定数据到泛型类(Dictionary)
- DataList数据的绑定
- Jquery动态绑定html5 datalist数据
- 怎样在gridview和datalist之类的绑定控件里控制显示 数据省略?
- datalist 绑定数据为空时,显示提示信息
- 数据绑定--Repeater, DataList, or GridView?
- ASP.NET数据绑定之DataList控件实战篇
- asp.net datalist绑定数据后可以上移下移实现示例
- ASP.NET 2.0 的数据绑定控件概述与区别(GridView、DetailsView、FormView 、Repeater、DataList)
- 数据绑定控件Repeater/GridView/DataList在前台显示正确的文本格式收藏
- Asp.net--数据绑定控件DataList
- ASP.NET 的数据绑定,DataList,Repeater 的绑定示例
- Gridview,datalist,repeater数据绑定控件使用说明
- ASP.NET 2.0 的数据绑定控件概述与区别(GridView、DetailsView、FormView 、Repeater、DataList)
- C# winform key value型数据如何绑定ComBox (hashtable,keyvaluepair,dictionary )
- 使用DataList控件绑定数据并实现分页