【发布时间】:2014-05-21 12:40:54
【问题描述】:
这是我的网页截图,有两个面板。第一个面板填充第二个面板中的网格视图。列总费用、注册费、分期付款、待处理费用是模板字段。 我想在待定费用栏的页脚中计算待定费用 = 总费用 - 注册费 - (分期付款总和)。我还想在页脚中显示分期付款总和。
谁能告诉我如何去做。
这是我得到的输出,下面是页面的源代码
<asp:TemplateField HeaderText="Total Fee">
<ItemTemplate>
<asp:Label ID="Lbl_TotalFee" runat="server" Text='<%# Eval("total_fee") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Registration Fee">
<ItemTemplate>
<asp:Label ID="LblRegFee" runat="server" Text='<%# Eval("reg_fee") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="LblInstallments" runat="server" Text="Total Installments"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Installments">
<ItemTemplate>
<asp:Label ID="Lbl_Installment" runat="server"
Text='<%# Eval("installments")%>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="LblTotalIns" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pending Fee">
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="LblFinalPendingFee" runat="server" ></asp:Label>
</FooterTemplate>
</asp:TemplateField>
这是后面的代码......
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
double sum = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
//double installments = (e.Data.DataItem as double).installments;
if (DataBinder.Eval(e.Row.DataItem, "installments") != DBNull.Value)
{
sum += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "installments"));
en.Fee_TotalSumOfInstallments = sum.ToString();
}
else
{
en.Fee_TotalSumOfInstallments = "nill";
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label LblTotalIns = (Label)e.Row.FindControl("LblTotalIns");
LblTotalIns.Text = en.Fee_TotalSumOfInstallments.ToString();
Label LblFinalPendingFee = (Label)e.Row.FindControl("LblFinalPendingFee");
double PendFee=(Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "total_fee"))-(Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "reg_fee"))+sum));
en.Fee_TotalPendingFee=PendFee.ToString();
LblFinalPendingFee.Text = en.Fee_TotalPendingFee.ToString();
//string abc = (Convert.ToInt32(e.Row.FindControl("Lbl_TotalFee")) - Convert.ToInt32(e.Row.FindControl("LblRegFee")) - total).ToString();
}
}
问题是未决费用总是计算为 0。我在哪里错了?请帮忙!
谢谢。
【问题讨论】:
标签: asp.net gridview templatefield