C # gridview footer Summary

Source: Internet
Author: User

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?
  1. If(E. Row. rowtype = datacontrolrowtype. datarow)
  2. {
  3. Sum + = convert. todecimal (databinder. eval (E. Row. dataitem,"Price"));
  4. // Here we can calculate the sum.
  5. }
  6. Else If(E. Row. rowtype = datacontrolrowtype. footer)
  7. {
  8. E. Row. cells [3]. Text ="Total :";
  9. E. Row. Cells E. Row. cells [4]. Text = sum. tostring ();
  10. }
 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 () ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.