日期:2014-05-18 浏览次数:20394 次
private int totalLevel = 1; //最大产品树级数
private DataView dvstore; //表视图
private void DrawTheTable()
{
Tbl2.CssClass = "store";
TableRow tr = new TableRow();
tr.BackColor = Color.Gray;
tr.ForeColor = Color.White;
TableCell tc5 = new TableCell();
TableCell tc1 = new TableCell();
tc5.ColumnSpan = totalLevel;
tc5.Text = "产品类别";
tc5.Width = 100 * totalLevel;
tc1.Text = "产品编号";
tr.Cells.Add(tc5);
tr.Cells.Add(tc1);
Tbl2.Rows.Add(tr);
DrawTheTableRows(dvstore, "0", 0, new TableRow());
}
private void DrawTheTableRows(DataView dv, string parentNo, int level, TableRow tr)
{
dv.Sort = "ParentNo";
DataRowView[] drvs = dv.FindRows(parentNo);
if (drvs.Length > 0)
{
for (int i = 0; i < drvs.Length; i++)
{
TableRow tbr;
if (i != 0)
{
tbr = new TableRow();
}
else
{
tbr = tr;
}
//判断是不是组,需要你自己做算法,比如可以用FindRows方法查看parentno是这个id的记录是是否大于1
if (Convert.ToBoolean(drvs[i]["IsGroup"].ToString()))
{
TableCell tc = new TableCell();
tc.BackC