龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

ASP.NET使用GridView分组相似的行的数据

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
GridView可以有分组功能,首先看下这次做的效果图: 实现以上GridView分组相似行的效果源代码如下: private int prevParentID = 0; //用于判断某一行的数据与上一行的数据的某个特征值是否发

GridView可以有分组功能,首先看下这次做的效果图:

实现以上GridView分组相似行的效果源代码如下:

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;
  }
 }
}

 

精彩图集

赞助商链接