效果:

代码:
的


private int prevParentID = 0; //用于判断某一行的数据与上一行的数据的某个特征值是否发生了变化,从而确定是否应该插入分组行。
protected void gvProblems_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView rowView = (DataRowView) e.Row.DataItem;
int parentID = (int) rowView["ParentID"];
if (parentID != prevParentID)
{
//insert row
Table tbl = (Table) gvProblems.Controls[0];
int newRowIndex = tbl.Rows.GetRowIndex(e.Row);
GridViewRow newRow = new GridViewRow(newRowIndex, newRowIndex, DataControlRowType.DataRow,
DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.Text = UIHelper.GetIssueTreeParentData(parentID);
cell.CssClass = "parent_tree_group";
newRow.Cells.Add(cell);
cell.ColumnSpan = gvProblems.Columns.Count;
tbl.Controls.AddAt(newRowIndex, newRow);
//
prevParentID = parentID;
}
}
}