Click here to Skip to main content
16,016,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


how to calculate sum base on selected checkbox in a gridview
Posted

1 solution

C#
int c =1;
int sum =0;

foreach (GridView row in GridView.Rows)
            {
                CheckBox cb = row.FindControl("chkStatus");
                //Find checkbox control
                //Only the controls that are checked
                if (cb != null && cb.Checked)
                {
                    sum = sum + row.Cells(c).Text;
                    //Sum previous cell value plus every next selected drow cell value

                    // Set the sum label text value

                }
            }

 txtSelected.Text = sum.ToString();
 
Share this answer
 
Comments
akilkrv 28-Nov-12 23:48pm    
Hi krunal,
it giving below compilation error how can i trace it.

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'System.Web.UI.WebControls.GridView' does not contain a definition for 'cells' and no extension method 'cells' accepting a first argument of type 'System.Web.UI.WebControls.GridView' could be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 334: if (cb != null && cb.Checked)
Line 335: {
Line 336: sum = sum + row.cells(c).Text;
Line 337: //Sum previous cell value plus every next selected drow cell value
Line 338:
[no name] 29-Nov-12 3:38am    
Include this namespace:
System.Web.UI.WebControls.GridView

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