Step 1: Show footer = "true" in the property of the gridview to display the footer of the gridview.
Step 2: Double-click an event on the property panel to automatically generate a gridview1_rowdatabound event.
Step 3: Define the variable private decimal sum = 0;
Step 4: Add in protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)Code.
View plaincopy to clipboardprint?
-
- If(E. Row. rowtype = datacontrolrowtype. datarow)
-
-
- {
-
- Sum + = convert. todecimal (databinder. eval (E. Row. dataitem,"Price"));
-
-
- // Here we can calculate the sum.
-
-
- }
-
-
- Else If(E. Row. rowtype = datacontrolrowtype. footer)
-
- {
-
-
- E. Row. cells [3]. Text ="Total :";
-
-
- E. Row. Cells E. Row. cells [4]. Text = sum. tostring ();
-
-
- }
If (E. row. rowtype = datacontrolrowtype. datarow) {sum + = convert. todecimal (databinder. eval (E. row. dataitem, "price"); // you can calculate the sum here} else if (E. row. rowtype = datacontrolrowtype. footer) {e. row. cells [3]. TEXT = "Total:"; E. row. cells E. row. cells [4]. TEXT = sum. tostring () ;}