一
要實現很簡單
先做一個簡單的例子理解一下這個類的使用
代碼
using System;
using System
using System
using System
using System
using System
namespace XLSoft
{
public class MyDataGrid
{
public string DataName
{
get
{
object o = ViewState[
if (o == null)
return
return (string)o;
}
set { ViewState[
}
protected override int CreateChildControls(IEnumerable dataSource
{
int itemCount =
if (dataBinding)
{
foreach (object obj in dataSource)
{
Label lbl = new Label();
lbl
Controls
itemCount++;
}
}
return itemCount;
}
}
}
<MYUI:MyDataGrid
代碼
protected void Page_Load(object sender
{
DataTable dt = new DataTable();
dt
DataRow dr
dr
DataRow dr
dr
dt
dt
this
this
}
二
上面的實驗只是做了實現數據源控件的功能
代碼
public class MyColunm
{
public MyColunm() { }
public MyColunm(string name
{
this
this
this
}
private string _name;
private string _headerText;
private string _format;
public string Format
{
get { return _format; }
set{ _format = value; }
}
public string HeaderText
{
get { return _headerText; }
set { _headerText = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
}
public class MyColunmCollection : List<MyColunm>{}
public class MyDataGrid
{
private MyColunmCollection _colunms = new MyColunmCollection();
public MyColunmCollection Colunms
{
get { return _colunms; }
}
protected override int CreateChildControls(IEnumerable dataSource
{
Table table = new Table();
if (dataBinding)
{
TableHeaderRow trHeader = new TableHeaderRow();
foreach (MyColunm col in Colunms)
{
TableHeaderCell cell = new TableHeaderCell();
cell
trHeader
}
table
foreach (object obj in dataSource)
{
TableRow tr = new TableRow();
foreach (MyColunm col in Colunms)
{
TableCell cell = new TableCell();
if (string
cell
else
cell
tr
}
table
}
}
Controls
return
}
}
三
簡單來說
關於ParseChildren
From:http://tw.wingwit.com/Article/program/net/201311/11912.html