如何在GridView的Footer内显示总计
展开全部
前台:
<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"是数据源的一个字段
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询