用头文件模板计算Gridview的页脚模板中的Grandtotal [英] Calculating Grandtotal in Footer Template of Gridview with Header Template

查看:97
本文介绍了用头文件模板计算Gridview的页脚模板中的Grandtotal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个使用标题模板的Gridview。现在我想在页脚模板中计算总计。代码如下: -



Hi,

I have a Gridview where I used header templates. Now I want to calculate Grand total in Footer Template. The code is below:-

protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {




if (e.Row.RowType == DataControlRowType.DataRow)
        {
            servchg  += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "servicechg"));
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblservchgamount = (Label)e.Row.FindControl("lblservchg");
            lblservchgamount.Text = servchg.ToString();
        }





}



现在的问题是我得到空白的Grandtotal专栏。调试时,我发现绕过条件e.Row.RowType == DataControlRowType.DataRow。



在Google中找不到任何带有页眉和页脚模板的Gridview示例。





如果有人知道,请发一些。





谢谢...



}

Now the problem is that I am getting blank Grandtotal column. When debugged I found out that condition "e.Row.RowType == DataControlRowType.DataRow" is bypassed.

Not found any example of a Gridview with both Header and Footer Template in Google .


Please post some, if anybody knows.


Thanks...

推荐答案

参考这篇文章

http://www.encodedna.com/2013/06/sum-of-gridview-column-in-footer.htm [ ^ ]


//////it is in aspx page

 <asp:gridview id="gvDetails" runat="server" autogeneratecolumns="False" showfooter="true" datakeynames="id" onrowdatabound="gvDetails_RowDataBound"  />
 
<columns>
<asp:templatefield itemstyle-horizontalalign="Center" footerstyle-horizontalalign="Center" xmlns:asp="#unknown">
                                <HeaderTemplate>
                                    Service Charge</HeaderTemplate>
                                <HeaderStyle  Width="15%" />
                                
                                <itemtemplate>
                                    <asp:label id="lblServChrgRows" runat="server" Text='<%#Eval("servicechg") %>'/>
                                </itemtemplate>

                                <footertemplate>
                                    <div style="text-align:right; padding-removed20px;line-height:18px;">
                                    <asp:label id="lblservchg" runat="server"  />                                      </div></footertemplate></asp:templatefield></columns>
 </asp:GridView>







它是apsx.cs的旁边代码






it is apsx.cs side code

 decimal servchg = 0;
protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {
     if (e.Row.RowType == DataControlRowType.DataRow)
        {  Label lblServChrgRows= (Label)e.Row.FindControl("lblServChrgRows");
                 if (!string.IsNullOrEmpty(lblServChrgRows.text))
                 { 
                servchg += Convert.ToDecimal(lblServChrgRows.text);
                }

            
        }
       
        if (e.Row.RowType == DataControlRowType.Footer)
        { 
            Label lblservchgamount = (Label)e.Row.FindControl("lblservchg");
            lblservchgamount.Text = servchg.ToString();
        }
    }


这篇关于用头文件模板计算Gridview的页脚模板中的Grandtotal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆