GridView相同内容合并单元格
2024-07-29 08:02:26 阅读次数:18
class,object
C# code
-
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class main : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{ // bind();
Gridview_RowSpan(GridView1);
}
public static void Gridview_RowSpan(System.Web.UI.WebControls.GridView gv)
{
// 合并单元格
for ( int i = 0 ; i < gv.Rows.Count - 1 ; i ++ )
{
int colnum = 1 ;
int j;
for (j = i + 1 ; j < gv.Rows.Count; j ++ )
{
if (gv.Rows[i].Cells[ 0 ].Text == gv.Rows[j].Cells[ 0 ].Text)
{
colnum ++ ;
gv.Rows[i].Cells[ 0 ].RowSpan = colnum;
gv.Rows[j].Cells[ 0 ].Visible = false ;
gv.Rows[i].Cells[ 1 ].RowSpan = colnum;
gv.Rows[j].Cells[ 1 ].Visible = false ;
gv.Rows[i].Cells[ 2 ].RowSpan = colnum;
gv.Rows[j].Cells[ 2 ].Visible = false ;
gv.Rows[i].Cells[ 3 ].RowSpan = colnum;
gv.Rows[j].Cells[ 3 ].Visible = false ;
gv.Rows[i].Cells[ 4 ].RowSpan = colnum;
gv.Rows[j].Cells[ 4 ].Visible = false ;
gv.Rows[i].Cells[ 5 ].RowSpan = colnum;
gv.Rows[j].Cells[ 5 ].Visible = false ;
gv.Rows[i].Cells[ 6 ].RowSpan = colnum;
gv.Rows[j].Cells[ 6 ].Visible = false ;
gv.Rows[i].Cells[ 7 ].RowSpan = colnum;
gv.Rows[j].Cells[ 7 ].Visible = false ;
gv.Rows[i].Cells[ 8 ].RowSpan = colnum;
gv.Rows[j].Cells[ 8 ].Visible = false ;
}
else
break ;
}
i = j - 1 ;
}
}
}
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.csdn.net/lee576/article/details/3289509,作者:lee576,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:初学Android,图形图像之使用Canvas,Paint绘图(二十五)
下一篇:澄清概念:委托---事件---事件处理