利用Asp.net 动态创建DataList ——C#
2011-06-22 15:23
501 查看
gv.HeaderTemplate= new createDL(ListItemType.Header); gv.ItemTemplate= new createDL(ListItemType.Item); gv.AlternatingItemTemplate= new createDL(ListItemType.AlternatingItem); gv.FooterTemplate= new createDL(ListItemType.Footer); DataTable dt = new DataTable(); gv.DataSource=dt; gv.DataBind(); public class createDL:ITemplate { public int itemcount=0; ListItemType TemplateType; public createDL(ListItemType type) { TemplateType = type; } public void InstantiateIn(Control container) { Literal lc = new Literal(); switch (TemplateType) { case ListItemType.Header: lc.Text="<TABLE border=1><TR><TH>Items</TH></TR>"; break; case ListItemType.Item: lc.Text = "<TR><TD>Item number: " + itemcount.ToString()+"</TD></TR>"; lc.DataBinding += new EventHandler(TemplateControl_Databinding); break; case ListItemType.AlternatingItem: lc.Text = "<TR><TD bgcolor=lightblue>Item number: " + itemcount.ToString() + "</TD></TR>"; break; case ListItemType.Footer: lc.Text = "</TABLE>"; break; } container.Controls.Add(lc); itemcount += 1; } public void TemplateControl_Databinding(object sender, System.EventArgs e) { Literal lc=(Literal)sender; DataListItem container = (DataListItem)lc.NamingContainer; lc.Text = lc.Text + DataBinder.Eval(container.DataItem, "Name"); lc.Text += "</TD></TR>"; } }
相关文章推荐
- 利用Asp.net 动态创建DataList
- 利用Asp.net 动态创建DataList--- VB
- 利用Asp.net 动态创建DataList[转]
- [转贴]利用Asp.net 动态创建DataList,通过继承 ITemplate
- asp.net(c#)动态创建一个文本框和按钮并取得文本框的值
- asp.net中利用ajax获取动态创建表中文本框的值
- 利用C#创建 IIS 站点并设置.NET Framework版本为ASP.NET 2.0 的方法(转)
- 在ASP.NET中利用HtmlTable动态创建表格
- c# asp .net 动态创建sql数据库表
- 利用C#创建 IIS 站点并设置.NET Framework版本为ASP.NET 2.0 的方法
- 【转】利用C#创建 IIS 站点并设置.NET Framework版本为ASP.NET 2.0 的方法(二) 转自孟子E章
- c# asp .net 动态创建sql数据库表的方法
- 利用C#创建 IIS 站点并设置.NET Framework版本为ASP.NET 2.0 的方法
- 利用C#创建 IIS 站点并设置.NET Framework版本为ASP.NET 2.0 的方法
- c# asp .net 动态创建sql数据库表
- asp.net C#动态添加创建生成button按钮控件没有触发执行响应click绑定事件处理
- 利用C#创建 IIS 站点并设置.NET Framework版本为ASP.NET 2.0 的方法(一)
- asp.net(c#)动态创建一个文本框和按钮并取得文本框的值
- asp.net教程-如何利用C#创建和调用DLL
- vs2003 asp.net中直接输出wml,并利用C#做动态页面的控制,不使用微软的移动控件