Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i want To count the Column values and then Display in Footer Template.
For that i wrote like this.
But i got the error "Object Reference not set to an instance of an object"

C#
DataTable table = dsProject_SH.Tables[1];
        decimal count = 0;
        foreach (DataRow dr in table.Rows)
        {

            count += Convert.ToDecimal(dr["Weightage"]);
        }

        Label lblWeightage = (Label)dg_Drawing_Appl.FooterRow.FindControl("lblWeightage");        
        lblWeightage.Visible = true;
        lblWeightage.Text = count.ToString();


I'm checking to "Count" data .It's fine But in highlighted line only i'm getting error can any one help me to do this.


Thanks in advance....
Posted

1 solution

Like the error says FindControl is not finding the "lblWeightage" control name, check the spelling for this matches where you defined it.
 
Share this answer
 
Comments
[no name] 1-Sep-12 4:47am    
I just copy & paste the control name from Footer Template Control
Mehdi Gholam 1-Sep-12 4:55am    
Debug your application and see which term is null when you move your mouse over it.

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