代码如下:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
private void GridViewFill(GridViewRowEventArgs e)
{
//获得部门Id
string departId = DataBinder.Eval(e.Row.DataItem, "UserInfo.departId").ToString();
DepartInfo depart = GetComponent.DepartInfoManager.FindDepartInfoById(int.Parse(departId));
e.Row.Cells[0].Text = depart.UserInfo.UserName;
e.Row.Cells[4].Text = depart.DepartName;
e.Row.Cells[5].Text = depart.BranchInfo.BranchName;
//获得签卡标记
e.Row.Cells[2].Text = (e.Row.Cells[2].Text.Trim().Equals("1")) ? "签到" : "签退";
//获得签卡描述
string signDesc = e.Row.Cells[3].Text.Trim();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewFill(e);
}
}
//单元格的处理
private void UnitOperate(GridView gridView)
{
string saveCell;//保存列
int lastCell;//最终列
if (gridView.Rows.Count > 0)
{
for (int i = 0; i < 6; i++)
{
//排除不合并的单元格
if (i != 1 && i != 2 && i != 3)
{
saveCell = gridView.Rows[0].Cells[i].Text;//获得第一行需合并数据
gridView.Rows[0].Cells[i].RowSpan = 1;//设初始合并值为1,每遇重复行自加并移动的新的行号获取数据
lastCell = 0;
for (int temp = 1; temp < gridView.Rows.Count; temp++)
{ //发现重复行将其合并
if (gridView.Rows[temp].Cells[i].Text == saveCell)
{
gridView.Rows[temp].Cells[i].Visible = false;
gridView.Rows[lastCell].Cells[i].RowSpan++;//合并
}
else
{//下一条用户记录
saveCell = gridView.Rows[temp].Cells[i].Text;//将其第一条记录保留,作为下一次比较用
lastCell = temp;//把行号保存
gridView.Rows[temp].Cells[i].RowSpan = 1;//开始新合并行
}
}
}
}
}
}
我已经成功的合并单元格了。。但是分页以后。发现点击第2页没有东西。。。哪位大哥可以帮帮我这位新手
合并单元格应该用脚本在前台来实现,可以看看我的博客
请问楼主,上面的问题解决了吗?能讲讲大概是怎样的实现思路吗?