This example demonstrates how calculate total price in GridView Control.

First, you will need to import the System.Data.SqlClient namespace.

The System.Data.SqlClient namespace contains the SqlConnection and SqlCommand Classes that we need in order to operate database.In order to run this example correctly, please modify uid and pwd of the connectionstring with the uid and pwd of your database.

We use the GridView1_RowDataBound1 event to do the work.

We then call the GridView1_RowDataBound1 to calculate every price.

The event occurs when a data row is bound to data in a GridView control.

The code as following:

The front end CalculateTotalPriceWithGridViewVB.aspx page looks something like this:

The flow for the code behind page is as follows: