如何为gridview合并行赋予颜色? [英] How to give color to the gridview merger rows ?
本文介绍了如何为gridview合并行赋予颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在网格视图中对网格视图中的一组行合并和应用颜色有疑问。
Ex:
我的格式如下。
Hi All,
I have a doubt in Grid view merging and applying color for one group of rows in gridview.
Ex:
I have a format like below.
S.No Acc No PatName Age CPT ICD1 ICD2 ICD3
1 12345 Maria 24 87452 142.2 214.2 741
85214 874.6 254.3 845
78451 254.1 241.9 852
2 23456 Test 23 78945 412.5 251.2 142
3 345678 Test1 25 87451 4123 254.2 741.1
92145 742.2 541.6 874.5
84512 254.1 256.3 362.8
现在我可以像gridview中的上述格式一样合并。但我想为每个替代行提供颜色。例如,S.No 1将是不同的颜色,而S.No 2应该是另一种颜色。
这是非常迫切的要求。请有人帮帮我。等待快速回复。
请在下面找到我的代码,用于合并gridview行。
Now i m able to merger like above format in gridview. But i want to give color for each alternative rows. For Example S.No 1 will be in different color and S.No 2 should be in another color.
It is very urgent requirement. Please anyone help me. Waiting for quick response.
Please find my Code below for merging a gridview rows.
public static void MergeRows(GridView gridView)
{
for (int rowIndex = gridView.Rows.Count-2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = gridView.Rows[rowIndex];
GridViewRow previousRow = gridView.Rows[rowIndex + 1];
GridViewRow nextpreviousRow = null;
for (int i = 4; i <= 5; i++)
{
string AccNo = ((Label)gridView.Rows[rowIndex].Cells[i].FindControl("lblAccountNo")).Text;
string PreAccNo = ((Label)gridView.Rows[rowIndex + 1].Cells[i].FindControl("lblAccountNo")).Text;
string BatId = ((Label)gridView.Rows[rowIndex].Cells[i + 1].FindControl("lblBatchId")).Text;
string PreBatId = ((Label)gridView.Rows[rowIndex + 1].Cells[i + 1].FindControl("lblBatchId")).Text;
if ((AccNo == PreAccNo) && (BatId == PreBatId))
{
for (int kl = 0; kl <= 28; kl++)
{
row.Cells[kl].RowSpan = previousRow.Cells[kl].RowSpan < 2 ? 2 :
previousRow.Cells[kl].RowSpan + 1;
for (int ip = 0; ip < gridView.Columns.Count; ip++)
{
if ((row.Cells[kl].RowSpan == 2))
{
previousRow.Style.Add("border-bottom-style", "solid");//
row.Style.Add("border-top-style", "solid");
}
else if ((row.Cells[kl].RowSpan == 3))
{
row.Style.Add("border-top-style", "solid");
row.Style.Add("border-bottom-style", "None");
previousRow.Style.Add("border-top-style", "None");
previousRow.Style.Add("border-bottom-style", "None");
}
else if ((row.Cells[kl].RowSpan == 4) || (row.Cells[kl].RowSpan == 6) || (row.Cells[kl].RowSpan == 7) || (row.Cells[kl].RowSpan == 8))
{
row.Style.Add("border-top-style", "solid");
row.Style.Add("border-bottom-style", "None");
previousRow.Style.Add("border-top-style", "None");
}
else if (row.Cells[kl].RowSpan == 5)
{
row.Style.Add("border-top-style", "solid");
row.Style.Add("border-bottom-style", "None");
nextpreviousRow.Style.Add("border-top-style", "None");
previousRow.Style.Add("border-top-style", "None");
previousRow.Style.Add("border-bottom-style", "None");
}
}
row.Cells[kl].BorderColor = System.Drawing.Color.Green;
previousRow.Cells[kl].Visible = false;
}
break;
}
else
{
// row.Style.Add("border-top-style", "solid");
}
}
}
}
推荐答案
您可以使用 GridView.AlternatingRowStyle Property [ ^ ],否则尝试使用CSS技巧 - 如 ASP中的备用行。 NET GridView,HTML5表 [ ^ ]。
另见 - 合并gridview行后应用交替颜色 [ ^ ],在您实施合并时处理行。
You can use GridView.AlternatingRowStyle Property[^], else try with CSS tricks as described here - Alternate Rows in ASP.NET GridView, HTML5 Tables[^].
Also see - Apply alternating color after merging gridview rows[^], which deals with rows when you are implementing merge.
这篇关于如何为gridview合并行赋予颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文