表格合并单元格【c#】

时间:2022-07-06 05:54:26

gridBranchInfo.DataSource = dtBranchViewList;
gridBranchInfo.DataBind();
Random random = new Random();
Color[] color = {Color.DarkSalmon, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Violet, Color.Honeydew,Color.IndianRed };

if (gridBranchInfo.Rows.Count > 0)
{
TableCell gridmd = gridBranchInfo.Rows[0].Cells[1];
for (int i = 1; i < gridBranchInfo.Rows.Count; i++)
{
TableCell gmid = gridBranchInfo.Rows[i].Cells[1];
if (gridmd.Text == gmid.Text)
{
gmid.Visible = false;
if (gridmd.RowSpan == 0)
{
gridmd.RowSpan = 1;
}
gridmd.RowSpan++;
gridmd.Font.Bold = true;
gridmd.ForeColor = color[random.Next(1, 7)];
gridmd.CssClass = "solids";
gridmd.VerticalAlign = VerticalAlign.Middle;
}
else
{
gridmd = gmid;
}
}
}

添加颜色:
<style type="text/css">

.solids {
border: 1px solid;
border-left: 2px solid;
}
</style>