网格视图asp.net中的页脚问题 [英] Grid view Footer problem in asp.net

查看:80
本文介绍了网格视图asp.net中的页脚问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  GridView1_RowDataBound1(对象发​​件人,GridViewRowEventArgs e)
{
int total = 0 ;

if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl_premium =(Label) e.Row.FindControl( lblpremium);
标签lbl_tot =(标签)e.Row.FindControl( lbltotal);
total + = int .Parse(lbl_premium.Text);

lbl_tot.Text = total.ToString( C,culInfo) .Remove( 0 2 )。Trim();
}
}



当我编译这段代码时,它没有进入if条件..

解决方案

为了在gridview的页脚中显示总数,您需要在gridview标记代码中添加FooterTemplate。然后只有你的if条件用于检查rowtype,因为页脚将匹配if(e.Row.RowType == DataControlRowType.Footer)。



PS :此外,您需要更改总计算 - 如果您正在执行的行类型是DataRow而不是Footer。



您可以参考以下链接



在asp.net的gridview页脚中显示总列数的总和 [ ^ ]



希望这有帮助...







添加链接文字以反映文章/质量保证标题。

更正了格式和语法问题。

[/编辑]


首先在Gridview中启用showfooter选项

 ShowFooter =  true  


您是否已将页脚模板添加到网格中,如果没有请先添加footerteplate



EditTemplate> FooterTemp晚

protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
    int total = 0;

    if (e.Row.RowType == DataControlRowType.Footer)
    {
        Label lbl_premium = (Label)e.Row.FindControl("lblpremium");
        Label lbl_tot=(Label)e.Row.FindControl("lbltotal");
        total += int.Parse(lbl_premium.Text);

        lbl_tot.Text = total.ToString("C", culInfo).Remove(0, 2).Trim();
    }
}


when i compile this code ,its not getting into the if condition..

解决方案

In order to show the total in the footer of the gridview you need to add the FooterTemplate in your gridview markup code. Then only your "if" condition will be for checking the rowtype as footer will match "if (e.Row.RowType == DataControlRowType.Footer)".

PS: Also, you need to change the total calculation- if rowtype is DataRow not Footer as you are doing currently.

You can refer the below link

Display sum of columns total in gridview footer in asp.net[^]

Hope this helps ...


[Edit member="Tadit"]
Link text added to reflect the Article/QA title.
Corrected formatting and grammatical issues.
[/Edit]


First to Enable showfooter option in Gridview

ShowFooter=true


Have you added footer template to your grid if not please first add footerteplate by

EditTemplate>FooterTemplate


这篇关于网格视图asp.net中的页脚问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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