DataList绑定数据到泛型类(Dictionary)
2008-10-09 09:27
393 查看
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;
}
}
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; } }
view plaincopy to clipboardprint?
<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>
<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>绑定到List的方式非常类似,这里不再给出代码
相关文章推荐
- DataList绑定数据到泛型类(Dictionary)
- DataList绑定数据到泛型类(Dictionary)
- DataList绑定数据到泛型类(Dictionary) 【转】
- DataList绑定数据到泛型类(Dictionary)
- DataList绑定数据到泛型类(Dictionary)
- datalist数据绑定时发生的事件
- 数据绑定控件收藏 DropDownList ListBox GridView DataList Repeater FormView DetailsView
- ASP.NET中对DataList控件进行数据绑定并分页
- 数据绑定控件收藏 DropDownList ListBox GridView DataList Repeater FormView DetailsView
- ASP.NET中的DataList控件编码实现数据绑定、删除、更新等操作
- ASP.NET 2.0 的数据绑定控件概述与区别(GridView、DetailsView、FormView 、Repeater、DataList)
- DataList 数据绑定,排版
- ASP.NET 2.0 的数据绑定控件概述与区别(GridView、DetailsView、FormView 、Repeater、DataList)
- ASP.NET中 DataList(数据列表)的使用前台绑定
- 《ASP.NET》数据绑定—DataList
- ASP.NET控件(gridview datalist等等 )后台绑定数据
- DataList的数据绑定
- 数据绑定控件之DataList
- Datalist嵌套datalist,页面传值,加密,数据绑定
- DataList中的HyperLink数据绑定和链接的写法