【问题标题】:GridView Footer row is nullGridView 页脚行为空
【发布时间】:2014-08-31 09:52:46
【问题描述】:

页脚设置为可见,我可以看到它正在创建。但是,当将总计(表格总和)传递给它时,会出现错误,指示 GridView2.FooterRow 为空... totTable 是指携带总计的 DataTable。

aspx:

ShowHeader="true" ShowFooter="true" FooterStyle-CssClass="FooterStyle"

cs:

 DataRow dr = totTable.Rows[0];
 foreach (DataControlField col in GridView2.Columns)
                {
                    foreach (DataColumn dc in totTable.Columns)
                    {
                        int i = GridView2.Columns.IndexOf(col);
                        GridView2.FooterRow.Cells[i].Text = dr[i].ToString();

                    }
                }

这背后的根本原因是什么?

【问题讨论】:

  • @Hyarantar 哦,是的...... dataTable Row.. 让我编辑帖子。
  • 好吧,我设法解决了。这主要是因为当我尝试访问页脚时 GridView2 尚未初始化 ..所以你去...

标签: c# asp.net gridview footer


【解决方案1】:

绑定gridview后使用如下代码:

    public void CountGrandTotal()
    {
        int sum = 0;
        for (int i = 0; i <grdproduct.Rows.Count ; i++)
        {
            Label lblprice = (Label)grdproduct.Rows[i].FindControl("Label5");

            sum += int.Parse(lblprice.Text);
        }
        Label lblgtotal = (Label)grdproduct.FooterRow.FindControl("Label7");
        lblgtotal.Text = sum.ToString();

【讨论】:

  • 我不确定您是否看到了我的最后一条评论。我已经解决了。不过还是谢谢。
【解决方案2】:

在 GridView 的 OnLoad 方法上添加页脚。

<asp:GridView ID="Gv"
  runat="server"     
  ShowFooter="true"
  OnLoad="Gv_Load">

【讨论】:

  • 只是转发你自己的答案@bonCodigo
猜你喜欢
  • 2010-10-30
  • 2011-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-20
  • 1970-01-01
  • 2015-03-04
  • 1970-01-01
相关资源
最近更新 更多