如何在GridView的Footer内显示总计?

marist 2007-04-03 05:04:54
如题,要详细代码,谢谢
...全文
843 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq756791021 2011-03-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 fxqyyzg 的回复:]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if(e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType ……
[/Quote]
这个就很好啊!LZ
dyhjjk 2007-04-04
  • 打赏
  • 举报
回复
study...
marist 2007-04-03
  • 打赏
  • 举报
回复
海同学的方法有点麻烦,多计算一行然后再减一次。西门同学的就好点,七三分了,,谢谢大家
lovehongyun 2007-04-03
  • 打赏
  • 举报
回复
fxqyyzg的方法可以实现
hy_lihuan 2007-04-03
  • 打赏
  • 举报
回复
if(e.Row.RowType == DataControlRowType.Footer)

主要就是这个!
leixueqiyi 2007-04-03
  • 打赏
  • 举报
回复

fxqyyzg(海冬青)(昨夜西风凋碧树。独上高楼,望尽天涯路)
正解
doggod2008 2007-04-03
  • 打赏
  • 举报
回复
前台:
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False"
OnRowDataBound="GridView1_RowDataBound"
ShowFooter="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="labelfirst" runat="server" Text='<%# Eval("first") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="labelAll" runat="server" Text="总计:"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台:
private int num = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView dr = e.Row.DataItem as DataRowView;
num += Convert.ToInt32(dr.Row["first"]);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
Label LabelAll = e.Row.FindControl("labelAll") as Label;
if (LabelAll != null)
{
LabelAll.Text += num.ToString();//"计算的总数,或者也可以单独计算";//
}
}
}
"first"是我数据源的一个字段
as13019625389 2007-04-03
  • 打赏
  • 举报
回复
楼上正解
fxqyyzg 2007-04-03
  • 打赏
  • 举报
回复
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if(e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.EmptyDataRow)

{

DataRowView drvBasicCountInfor = (DataRowView)e.Row.DataItem;

iNumber = Convert.ToInt32(drvBasicCountInfor[7]);

iMoney = Convert.ToInt32(drvBasicCountInfor[8]);

}



// 生成总计

//totalNumber += iMemberNo;

//totalMoney += iVisitNo;

totalNumber += iNumber;

totalMoney += iMoney;





if(e.Row.RowType == DataControlRowType.Footer)

{

e.Row.Cells[6].Text = "总计";

e.Row.Cells[7].Text = Convert.ToString(totalNumber-iNumber);

e.Row.Cells[8].Text = Convert.ToString(totalMoney-iMoney);

}



}

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧