需求是这样的:
我的gridview是接收前一页的参数来动态显示的,也就是说gridview的列是不确定的。我想在gridview中建个footer行,不管我的gridview是多少列,footer行只显示为一列(即合并footer列),并在footer行中对gridview求总计(即gridview总的行数)。
如何实现呢?
PS:我是用C#语言进行程序编写的。
我的gridview是接收前一页的参数来动态显示的,也就是说gridview的列是不确定的。我想在gridview中建个footer行,不管我的gridview是多少列,footer行只显示为一列(即合并footer列),并在footer行中对gridview求总计(即gridview总的行数)。
如何实现呢?
PS:我是用C#语言进行程序编写的。
解决方案 »
- 在线等待<meta http-equiv="Content-Type" content="text/html"; charset=ISO-8859-1"/>
- AJAX问题,如何用代码添加AsyncPostBackTrigger并使之起作用
- 求一个正则表达式写法
- P.Response.Cookies.Remove(CookieName)为什么不能正确删除Cookies?
- 帮忙看看哪里错了
- 请教高手一个问题
- 哪位大哥有可以知道ip来源的流量统计系统?能不能个小弟一套?
- 如何在TreeView里插入CheckBox
- 怎样实现asp.net和asp之间的参数传递?
- 注销界面中,如何让cookie的数据消失!在线等!
- visual studio 2005 在那里设置显示的行号
- vs2008 启用调试的时候,提示“无法连接到 ASP.NET Development Server”,这该怎么办呀??
这个方法就行
footer里其实是和普通字段一样的
那么你就可以用“求和”算出有多少条
{
if (e.Row.RowType == DataControlRowType.Footer )
{
e.Row.Cells[0].Text = "合计:";
e.Row.Cells[4].ColumnSpan=4;
//把其他列隐藏就行了!
}
}
如果是当前页总计,只有绑定数据后再循环gridview获取数据再相加,或者sum数据集的top多少。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
sum += Convert.ToDouble(e.Row.Cells[6].Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[5].Text = "总薪水为:";
e.Row.Cells[6].Text = sum.ToString();
e.Row.Cells[3].Text = "平均薪水为:";
e.Row.Cells[4].Text = ((int)(sum / GridView1.Rows.Count)).ToString();
}
}
把你的总计放到最后一列!!
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
TableCellCollection cells = e.Row.Cells;
for (int i = 0; i < cells.Count; i++)
cells[i].CssClass = "你的css";//消除边框,设置背景色 cells[cells.Count-1].Text="总计:"+你的变量
cells[cells.Count - 1].Wrap = false;
}
}
谢谢你,我根据你的代码稍微修改了一下,得到了我想要的总计,但还是没有进行合并footer。望指教。谢谢!
我的修改如下:
if (e.Row.RowType == DataControlRowType.Footer)
{
TableCellCollection cells = e.Row.Cells;
for (int i = 0; i < cells.Count; i++)
cells[cells.Count - 1].Text = "总计:"+this.GridView1.Rows.Count+"条";
cells[cells.Count - 1].Wrap = false;
}
{
TableCell cell = new TableCell();
cell.ColumnSpan = e.Row.Cells.Count;
cell.Text = "总计:条数";(这里可以随便写,相当于已将单元格合并了)
cell.HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells.Clear();
e.Row.Cells.Add(cell);
}