Gridview中合并单元格,某字段的内容相同时如何只显示一个,屏蔽相同列或行的内容(转)...

Gridview中某字段的内容相同时如何只显示一个,屏蔽相同列或行的内容

 

   1:   
   2:      #region 合并单元格 合并某一行的所有列
   3:      ///  <summary> 
   4:      ///  合并GridView中某行相同信息的行(单元格)
   5:      ///  </summary> 
   6:      ///  <param  name="GridView1">GridView对象</param> 
   7:      ///  <param  name="cellNum">需要合并的行</param>
   8:      public static void GroupRow(GridView GridView1, int rows)
   9:      {
  10:          TableCell oldTc = GridView1.Rows[rows].Cells[0];
  11:          for (int i = 1; i < GridView1.Rows[rows].Cells.Count; i++)
  12:          {
  13:              TableCell tc = GridView1.Rows[rows].Cells[i];  //Cells[0]就是你要合并的列
  14:              if (oldTc.Text == tc.Text)
  15:              {
  16:                  tc.Visible = false;
  17:                  if (oldTc.ColumnSpan == 0)
  18:                  {
  19:                      oldTc.ColumnSpan = 1;
  20:                  }
  21:                  oldTc.ColumnSpan++;
  22:                  oldTc.VerticalAlign = VerticalAlign.Middle;
  23:              }
  24:              else
  25:              {
  26:                  oldTc = tc;
  27:              }
  28:          }
  29:      }
  30:      #endregion
  31:      #region 合并单元格 合并一行中的几列
  32:      /// <summary>
  33:      /// 合并单元格 合并一行中的几列
  34:      /// </summary>
  35:      /// <param name="GridView1">GridView ID</param>
  36:      /// <param name="rows">行</param>
  37:      /// <param name="sCol">开始列</param>
  38:      /// <param name="eCol">结束列</param>
  39:      public static void GroupRow(GridView GridView1, int rows, int sCol, int eCol)
  40:      {
  41:          TableCell oldTc = GridView1.Rows[rows].Cells[sCol];
  42:          for (int i = 1; i < eCol - sCol; i++)
  43:          {
  44:              TableCell tc = GridView1.Rows[rows].Cells[i + sCol];  //Cells[0]就是你要合并的列
  45:              tc.Visible = false;
  46:              if (oldTc.ColumnSpan == 0)
  47:              {
  48:                  oldTc.ColumnSpan = 1;
  49:              }
  50:              oldTc.ColumnSpan++;
  51:              oldTc.VerticalAlign = VerticalAlign.Middle;
  52:          }
  53:      }
  54:      #endregion
  55:      #region 合并单元格 合并某一列所有行
  56:      /// <summary>
  57:      /// 合并GridView中某列相同信息的行(单元格)
  58:      /// </summary>
  59:      /// <param name="GridView1"></param>
  60:      /// <param name="cellNum"></param>
  61:      public static void GroupCol(GridView GridView1, int cols)
  62:      {
  63:          if (GridView1.Rows.Count < 1 || cols > GridView1.Rows[0].Cells.Count - 1)
  64:          {
  65:              return;
  66:          }
  67:          TableCell oldTc = GridView1.Rows[0].Cells[cols];
  68:          for (int i = 1; i < GridView1.Rows.Count; i++)
  69:          {
  70:              TableCell tc = GridView1.Rows[i].Cells[cols];
  71:              if (oldTc.Text == tc.Text)
  72:              {
  73:                  tc.Visible = false;
  74:                  if (oldTc.RowSpan == 0)
  75:                  {
  76:                      oldTc.RowSpan = 1;
  77:                  }
  78:                  oldTc.RowSpan++;
  79:                  oldTc.VerticalAlign = VerticalAlign.Middle;
  80:              }
  81:              else
  82:              {
  83:                  oldTc = tc;
  84:              }
  85:          }
  86:      }
  87:      #endregion
  88:      #region 合并单元格 合并某一列中的某些行
  89:      /// <summary>
  90:      /// 合并单元格 合并某一列中的某些行
  91:      /// </summary>
  92:      /// <param name="GridView1">GridView ID</param>
  93:      /// <param name="cellNum">列</param>
  94:      /// <param name="sRow">开始行</param>
  95:      /// <param name="eRow">结束列</param>
  96:      public static void GroupCol(GridView GridView1, int cols, int sRow, int eRow)
  97:      {
  98:          if (GridView1.Rows.Count < 1 || cols > GridView1.Columns.Count - 1)
  99:          {
 100:              return;
 101:          }
 102:          TableCell oldTc = GridView1.Rows[sRow].Cells[cols];
 103:          for (int i = 1; i < eRow - sRow; i++)
 104:          {
 105:              TableCell tc = GridView1.Rows[sRow + i].Cells[cols];
 106:              tc.Visible = false;
 107:              if (oldTc.RowSpan == 0)
 108:              {
 109:                  oldTc.RowSpan = 1;
 110:              }
 111:              oldTc.RowSpan++;
 112:              oldTc.VerticalAlign = VerticalAlign.Middle;
 113:          }
 114:      }
 115:      #endregion

原文地址

转载于:https://www.cnblogs.com/Junelee1211/archive/2011/09/05/2167219.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值