hima
hima

Reputation: 620

how to calculate column sum in asp .net gridview without using footer row?

I have a GridView with one column showing cost. I would like to sum this cost and display as billing amount. upon adding/deleting a row billing amount should be updated.

I am using asp .net c#.

Upvotes: 0

Views: 2680

Answers (2)

jijomon
jijomon

Reputation: 1

protected void txtUnitPrice_TextChanged(object sender, EventArgs e)
{
    try
    {
        DataSet dset3 = new DataSet();
        GridViewRow currentRow = (GridViewRow)((TextBox)sender).Parent.Parent;
        TextBox qty = (TextBox)currentRow.FindControl("txtqty");
        TextBox qty1 = (TextBox)currentRow.FindControl("txtUnitPrice");
        string a = qty.Text;
        TextBox totalprice = (TextBox)currentRow.FindControl("txttotal");
        totalprice.Text = (Double.Parse(qty1.Text) * Double.Parse(qty.Text)).ToString();

    }
    catch (Exception ex)
    {

    }

}

Upvotes: -1

Hassan Mokdad
Hassan Mokdad

Reputation: 5902

You should do it at rowDataBound event, where you will be able to access each cell at the row being bound at the moment and sum the values into a variable.

An Alternative way is to directly calculate the values from the Database

Upvotes: 2

Related Questions