GridView相同内容合并单元格

C# code
  
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->
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 ;
}
}

}



你可能感兴趣的:(GridView)