private void CreateTable(Table tab, DataTable dt, int cellCount)
{
if (dt == null)
{
return;
}
else
{
if (dt.Rows.Count < 0)
{
tab.Visible = false;
}
else
{
tab.Visible = true;
tab.Attributes.Add("width", "95%");
tab.Attributes.Add("bodercolor", "#999999");
tab.Style.Add("border-collapse", "collapse");
tab.Attributes.Add("border", "1");
tab.Attributes.Add("cellSpacing", "0");
tab.Attributes.Add("cellPadding", "0");
tab.BorderStyle = BorderStyle.Solid;
tab.BorderColor = Color.FromArgb(153, 153, 153);
//bordercolor=#999999 style=border-collapse:collapse
int rowCount;
int recordCount = dt.Columns.Count;
if (recordCount % cellCount == 0)
{
rowCount = recordCount / cellCount;
}
else
{
rowCount = recordCount / cellCount + 1;
}
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < rowCount; j++)
{
TableRow r = new TableRow();
r.Attributes.Add("height", "10px");
r.Attributes.Add("bodercolor", "#999999");
r.BorderStyle = BorderStyle.Solid;
r.BorderWidth = 1;
r.BorderColor = Color.FromArgb(153, 153, 153);
r.Attributes.Add("onmouseover", @"this.style.backgroundColor='79c5ea'");
r.Attributes.Add("onmouseout", @"this.style.backgroundColor='ffffff'");
//添加文本 到新单元格
for (int k = 0; k < cellCount;k++)
{
if (cellCount * j + k < recordCount)
{
int x = cellCount * j + k;
this.NewCell(dt.Columns[cellCount * j + k].ColumnName.ToString().Trim(), r,cellCount);
this.NewCell(dt.Rows[i][cellCount * j + k].ToString().Trim(), r,cellCount);
}
else
{
this.NewCell("", r, cellCount);
this.NewCell("", r, cellCount);
}
}
tab.Rows.Add(r);
}
TableRow r1 = new TableRow();
r1.Attributes.Add("height", "20px");
r1.Attributes.Add("bodercolor", "#999999");
r1.BorderStyle = BorderStyle.Solid;
r1.BorderWidth = 1;
r1.BorderColor = Color.FromArgb(153, 153, 153);
r1.Attributes.Add("onmouseover", @"this.style.backgroundColor='ff0000'");
r1.Attributes.Add("onmouseout", @"this.style.backgroundColor='ffffff'");
tab.Rows.Add(r1);
}
}
}
}
private void NewCell(string Text, TableRow r, int cellCount)
{
TableCell c = new TableCell();
c.Style.Add("width", Convert.ToString(100 / (2 * cellCount)) + "%");
c.BorderColor = Color.FromArgb(153, 153, 153);
c.BorderStyle = BorderStyle.Solid;
c.BorderWidth = 1;
c.Attributes.Add("bodercolor", "#999999");
c.Style.Add("border-collapse", "collapse");
c.Attributes.Add("bodercolor", "#ff0000");
c.Text = Text;
//c.Attributes.Add("onmouseover", @"this.style.backgroundColor='79c5ea'");
//c.Attributes.Add("onmouseout", @"this.style.backgroundColor='ffffff'");
r.Cells.Add(c);
}