菜鸟中的菜

导航

合并Gridview中的一列相同数据的行

合并所有列
 /// <summary>
/// 队所有列进行合并
/// </summary>
/// <param name="gridview"></param>
public static void MergerRos(GridView gridview)
{
for (int rowIndex = grvGoodsShow.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = grvGoodsShow.Rows[rowIndex];
GridViewRow previousRow = grvGoodsShow.Rows[rowIndex + 1];
for (int i = 0; i < length; i++)
{
if (row.Cells[i].Text == previousRow.Cells[i].Text)
{
row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 :
previousRow.Cells[i].RowSpan + 1;
previousRow.Cells[i].Visible = false;
}
}



}
}

 

View Code
/// <summary>
/// 合并某一列数据相同的行
/// </summary>
/// <param name="gridview">Gridview</param>
/// <param name="i">合并的那一列(索引)</param>
public static void MergerRos(GridView gridview,int i)
{
for (int rowIndex = grvGoodsShow.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = grvGoodsShow.Rows[rowIndex];
GridViewRow previousRow = grvGoodsShow.Rows[rowIndex + 1];
if (row.Cells[i].Text == previousRow.Cells[i].Text)
{
row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 :
previousRow.Cells[i].RowSpan + 1;
previousRow.Cells[i].Visible = false;
}


}
}

 

posted on 2012-03-30 16:58  菜中菜  阅读(338)  评论(0编辑  收藏  举报