首页 > 技术文章 > 表格合并单元格【c#】

liuguiqing 2021-09-06 13:35 原文

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>

推荐阅读