如何在GridView的Footer内显示总计
1个回答
2015-06-21 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517189
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
前台:
<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 "是我数据源的一个字段
<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 "是我数据源的一个字段
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询