前台:
<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"是数据源的一个字段
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦