【问题标题】:GridView footer not workingGridView 页脚不起作用
【发布时间】:2011-11-15 12:48:07
【问题描述】:

我想在 GridView 页脚中显示总计 - 那里没有什么异常。我已经按照 Microsoft 网站上的示例进行了操作,但它不起作用:

<asp:GridView ID="gvTimeOverview" DataSourceID="sdsTimeOverview" AutoGenerateColumns="false" ShowFooter="true" CssClass="gridview" runat="server">
            <Columns>
                <asp:BoundField DataField="DateTimeAdded" HeaderText="Date" DataFormatString="{0:dd/MM/yyyy}" />
                <asp:BoundField DataField="DateTimeAdded" HeaderText="Time" DataFormatString="{0:HH:mm}" />
                <asp:BoundField DataField="TimeToAdd" HeaderText="Mins Allocated" />
            </Columns>    
        </asp:GridView>

代码:

protected void gvTimeOverview_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        totalMins += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TimeToAdd"));
    }
    else if (e.Row.RowType == DataControlRowType.Footer)
    {
        e.Row.Cells[0].Text = "Totals:";
        e.Row.Cells[1].Text = totalMins.ToString();
        e.Row.ForeColor = Color.Black;
    }
}

知道为什么吗?

【问题讨论】:

  • 条件if (e.Row.RowType == DataControlRowType.Footer) 是否已通过?
  • 你能详细说明不工作的部分吗? totalMins 在调试时有任何价值吗?
  • sll - 不,没有命中该行的断点,但我不知道为什么。 Niranjan - 那是我遵循的指南。

标签: c# asp.net gridview


【解决方案1】:

未附加事件处理程序。

<asp:GridView 
       ID="gvTimeOverview" 
       DataSourceID="sdsTimeOverview" 
       AutoGenerateColumns="false" 
       ShowFooter="true" 
       CssClass="gridview" 
       runat="server"
       onrowdatabound="gvTimeOverview_RowDataBound">
....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    相关资源
    最近更新 更多