GridView控件与合并单元格

问题描述:

我需要显示在某些列合并行网格视图的数据。请帮我prepare在下面定义的格式网格视图:

I need to display data in grid view with merged rows for some columns. Please help me to prepare a grid view in below defined format:

和原始数据来自数据库是在以下格式:

And the original data comes from database is in below format:

请帮我找最好的方式动态地,高效地完成这个任务。

Please help me to find best way for doing this task dynamically and efficiently.

您将不得不使用 ROWSPAN

请参考以下code它:

protected void GridView1_DataBound1(object sender, EventArgs e)
{
  for (int rowIndex = GridView1.Rows.Count - 2;
                                     rowIndex >= 0; rowIndex--)
  {
    GridViewRow gvRow = GridView1.Rows[rowIndex];
    GridViewRow gvPreviousRow = GridView1.Rows[rowIndex + 1];
    for (int cellCount = 0; cellCount < gvRow.Cells.Count;
                                                  cellCount++)
    {
     if (gvRow.Cells[cellCount].Text ==
                            gvPreviousRow.Cells[cellCount].Text)
     {
       if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
       {
         gvRow.Cells[cellCount].RowSpan = 2;
       }
       else
       {
        gvRow.Cells[cellCount].RowSpan =
            gvPreviousRow.Cells[cellCount].RowSpan + 1;
       }
       gvPreviousRow.Cells[cellCount].Visible = false;
    }
   }
}

全球化志愿服务青年:

https://sites.google.com/site/learning6329/asp-net/gridview-merge-cells

画报例如在问:

http://marss.co.ua/MergingCellsInGridView.aspx