本文介绍了Gridview页脚计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
试图创建一个页脚计算器.现在的问题是,跳过了if()statemets.这有什么想法吗?检查以下代码:
Hi guys
Trying to create a footer calculator. Problem is now the if() statemets are skiped. any ideas Y this hapens? Check the code below:
protected void grvTravelClaims_RowDataBound(object sender, GridViewRowEventArgs e)
{
decimal _total = 0.0M;
int totalItems = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblKillometers = (Label)e.Row.FindControl("lblKillometers");
decimal killometers = Decimal.Parse(lblKillometers.Text);
_total += killometers;
totalItems += 1;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotalKillometers = (Label)e.Row.FindControl("lblTotalKillometers");
lblTotalKillometers.Text = _total.ToString();
}
}
推荐答案
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCommand="GridView1_RowCommand" OnRowEditing="GridView1_RowEditing"/>
}
关键是您需要将代码从Page_Load移到Page_Init.在Page_Load中添加的内容仅可用于一次回发的生命周期.
Key thing is that you need to move your code from Page_Load to Page_Init. Things added in the Page_Load last only for the lifecycle of one postback.
protected void Page_Load(object sender, EventArgs e)
{
BindGridView();
}
这篇关于Gridview页脚计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!