How can I get the sum total of a column in the gridview to a textbox outside the gridview?

user3985746 picture user3985746 · Nov 27, 2014 · Viewed 12.8k times · Source

In asp.net C#, How can I get the sum total of a column in the gridview to a textbox outside the gridview?

Note: Gridview data is not coming from any database it is being entered manually by the user.

Answer

ALOK picture ALOK · Nov 27, 2014

Call this Method on some button click or on new row creation or whatever event you want to

    private void GrandTotal()
    {
     float GTotal = 0f;
     for (int i = 0; i < GridView1.Rows.Count; i++)
     {
        String total = (GridView1.Rows[i].FindControl("lblTotal") as Label).Text;
        GTotal += Convert.ToSingle(total);
     }
     txtTotal.text=GTotal.toString();
    }

Hope i helped :D