当我试图在页脚中显示总数时,它不显示。网格视图出现但没有页脚我不知道我想念但我知道没有错误但是页脚没有显示
我的HTML:
<asp:TemplateField HeaderText="debit">
<ItemTemplate>
<asp:Label ID="lblDebAmount" runat="server" Text='<%# (Eval("v_flag").ToString() =="d" ) ? string.Format("{0:0.000}",float.Parse(Eval("v_amount").ToString())): "0.000" %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="totallblDebAmount" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#336699" Font-
Bold="True" ForeColor="White" HorizontalAlign="Left" />
<HeaderStyle BackColor="#336699" Font-Bold="True" ForeColor="White"
HorizontalAlign="Left" />
我的代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
decimal totalPrice = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblDebAmount = (Label)e.Row.FindControl("lblDebAmount");
decimal debtotal = Decimal.Parse(lblDebAmount.Text);
totalPrice += debtotal;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label totallblCAmount = (Label)e.Row.FindControl("totallblCAmount");
totallblCAmount.Text = totalPrice.ToString();
}
}
答案 0 :(得分:0)
尝试修改
Label totallblCAmount = (Label)e.Row.FindControl("totallblCAmount");
是
Label totallblCAmount = (Label)e.Row.FindControl("totallblDebAmount");