模板字段帮助! [英] Template field help!
本文介绍了模板字段帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的gridview内,列定义如下
inside my gridview the columns are defined as follows
<asp:TemplateField HeaderText="Amount" HeaderStyle-Width ="100px" FooterStyle-HorizontalAlign="right">
<ItemTemplate><%# Eval("amount")%></ItemTemplate>
</asp:TemplateField>
我想获取我正在使用for循环的gridview中所有行的总数.
但是我无法使用findcontrol获取金额列的值.
i want to get the total amount of all rows in my gridview for which i am using a for loop.
but i am unable to get the value of my amount column using findcontrol.
推荐答案
试试以下
Hi,
Try the following
decimal priceTotal = 0;
void detailsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, _
"amount"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "Totals:";
// for the Footer, display the running totals
e.Row.Cells[1].Text = priceTotal.ToString("c");
}
}
希望这会有所帮助....
Hope this helps....
嗨
尝试使用ItemTemplate内的标签绑定您的金额
Hi
Try binding your amount using a label inside your ItemTemplate
<asp:TemplateField HeaderText="Amount" HeaderStyle-Width="100px" FooterStyle-HorizontalAlign="right">
<ItemTemplate>
<asp:Label ID="lblAmount" runat="server" Text='<%# Eval("Amount")%>'></asp:Label></ItemTemplate>
</asp:TemplateField>
然后在按钮上单击
And on button click
protected void btnTotal_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in yourGridID.Rows)
{
Total+=double.Parse(((Label)row.FindControl("lblAmount")).Text);
}
yourLabelID.Text = Total.ToString();
}
希望这会有所帮助....
Hope this helps....
这篇关于模板字段帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文