Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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..
Posted
Updated 6-Nov-13 18:22pm
v2
Comments
Rahul_Pandit 7-Nov-13 0:23am    
can u check what value of e.Row.RowType is coming in debug mode?Please put your aspx code also.
Prasad Khandekar 7-Nov-13 0:26am    
Hello Jhonnie,

Is function name GridView1_RowDataBound1 is correct or should it be GridView1_RowDataBound?

Regards,
JoCodes 7-Nov-13 1:22am    
Post your gridview design markup too ...
Member 10257374 7-Nov-13 5:36am    
Hi johinne,
Please post your gridview design code and .cs code
then only we can try to solve your problem

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]
 
Share this answer
 
v3
First to Enable showfooter option in Gridview
C#
ShowFooter=true
 
Share this answer
 
Have you added footer template to your grid if not please first add footerteplate by

EditTemplate>FooterTemplate
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900