GridView页脚不工作

本文关键字:工作 GridView | 更新日期: 2023-09-27 18:14:45

我想在GridView页脚显示一个总数-没有什么不寻常的。我已经遵循了微软网站上的示例,但它不起作用:

<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;
    }
}

知道为什么吗?

GridView页脚不工作

未附加事件处理程序。

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