1
我想在GridView頁腳中顯示一個總數 - 在那裏沒什麼不尋常的。我已經按照Microsoft網站上的例子,但它不工作: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;
}
}
任何想法,爲什麼?
條件'if(e.RowType == DataControlRowType.Footer)''過去了嗎? – sll
你可以詳細說明*不是工作部分*嗎?在調試時'totalMins'有什麼價值? – V4Vendetta
http://msdn.microsoft.com/en-us/library/ms972833.aspx –