//单元格要合并的行数
public int intRowSpan = 1;
//开始合并的索引值
public int intIndex = 0;
//记录第一列相等的条件
private string strText = "";
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex == 0)
{
strText = e.Row.Cells[0].Text;
}
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != 0)
{
if (e.Row.Cells[0].Text == strText)
{
intRowSpan++;
GridView1.Rows[intIndex].Cells[0].RowSpan = intRowSpan;
e.Row.Cells[0].Visible = false;
}
else
{
intRowSpan = 1;
intIndex = e.Row.RowIndex;
}
strText = e.Row.Cells[0].Text;
} }
上面这段代码是实现gridview合并行的代码,代码是可以用的,我想把void GridView1_RowDataBound事件里的写成一个方法,以后可以直接调用了,因为我有可能第一列、第二列、第三列的行也要合并,不可能合一次写一次,不知道怎么写,望哥哥们帮下我
public int intRowSpan = 1;
//开始合并的索引值
public int intIndex = 0;
//记录第一列相等的条件
private string strText = "";
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex == 0)
{
strText = e.Row.Cells[0].Text;
}
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != 0)
{
if (e.Row.Cells[0].Text == strText)
{
intRowSpan++;
GridView1.Rows[intIndex].Cells[0].RowSpan = intRowSpan;
e.Row.Cells[0].Visible = false;
}
else
{
intRowSpan = 1;
intIndex = e.Row.RowIndex;
}
strText = e.Row.Cells[0].Text;
} }
上面这段代码是实现gridview合并行的代码,代码是可以用的,我想把void GridView1_RowDataBound事件里的写成一个方法,以后可以直接调用了,因为我有可能第一列、第二列、第三列的行也要合并,不可能合一次写一次,不知道怎么写,望哥哥们帮下我
解决方案 »
- 冰天雪地跪地求教
- 求助:其他用户正在看的.. 我最近看的...怎么实现?
- Net网站没有Webconfig配置文件能否运行?
- 怎么样能在另一个新页打开,原面又不会刷新?要求是在.cs文件中写
- 关于DataGrid的两个简单的小问题
- IIS无法运行.aspx文件了
- ASP和ASP.NET在安装上有什么区别!
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 我想将二维数组每个值导出 应该怎么做呢 如下:
- 思规---------你究竟是何方神圣???小弟对你的景仰就如滔滔江水,连绵不决
- html控件动态加载innerhtml后,FindControl找不到里面的控件
- 求一个画流程图的软件.
- 求助:后台sql语句参数问题
这么复杂的东西用table更灵活。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
this.GvRowMerge();
}public void GvRowMerge(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex == 0)
{
strText = e.Row.Cells[0].Text;
}
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != 0)
{
if (e.Row.Cells[0].Text == strText)
{
intRowSpan++;
GridView1.Rows[intIndex].Cells[0].RowSpan = intRowSpan;
e.Row.Cells[0].Visible = false;
}
else
{
intRowSpan = 1;
intIndex = e.Row.RowIndex;
}
strText = e.Row.Cells[0].Text;
}}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
this.GvRowMerge(sender,e);
}