自定义的集合类
///
1<summary>
2/// Collection 的摘要说明。
3/// </summary>
public class Collection : System.Collections.CollectionBase
{
public Collection()
{
for(int i = 0;i < 10;i++)
{
base.InnerList.Add(new Element(i,string.Format("a[{0}]",i)));
}
}
}
集合元素类
public class Element
{
private string name;
public string ValueName
{
get{return name;}
}
private int valu;
public int Value
{
get{return valu;}
}
public Element(int val,string nam)
{
name = nam;
valu = val;
}
}
aspx的后置代码
///
1<summary>
2/// WebForm1 的摘要说明。
3/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.DataSource = new Collection();
DataGrid1.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///
1<summary>
2/// 设计器支持所需的方法 - 不要使用代码编辑器修改
3/// 此方法的内容。
4/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
aspx页的html代码
1<body ms_positioning="FlowLayout">
2<form id="Form1" method="post" runat="server">
3<asp:datagrid autogeneratecolumns="False" id="DataGrid1" runat="server" width="224px">
4<columns>
5<asp:templatecolumn headertext="名称">
6<itemtemplate>
7<asp:label runat="server" text='```
8# DataBinder.Eval(Container, "DataItem.ValueName")
9```'>
10</asp:label>
11</itemtemplate>
12<edititemtemplate>
13<asp:textbox runat="server" text='```
14# DataBinder.Eval(Container, "DataItem")
15```'>
16</asp:textbox>
17</edititemtemplate>
18</asp:templatecolumn>
19<asp:templatecolumn headertext="数字">
20<itemtemplate>
21<asp:label runat="server" text='```
22# DataBinder.Eval(Container, "DataItem.Value")
23```'>
24</asp:label>
25</itemtemplate>
26<edititemtemplate>
27<asp:textbox runat="server" text='```
28# DataBinder.Eval(Container, "DataItem")
29```'>
30</asp:textbox>
31</edititemtemplate>
32</asp:templatecolumn>
33</columns>
34</asp:datagrid>
35</form>
36</body>