views:

167

answers:

1

i have a gridview

' /> Total

my code behind :

protected void btnGetTotal_Click(object sender, EventArgs e)
{
    int Rowindex = 0;

    StringCollection sc = new StringCollection();

    if (ViewState["CurrentTable"] != null)
    {
        DataTable dtCurrenttable = (DataTable)ViewState["CurrentTable"];

        if (dtCurrenttable.Rows.Count > 0)
        {
            for (int i = 1; i <= dtCurrenttable.Rows.Count; i++)
            {
                TextBox txtFeesAmount = (TextBox)gvSales.Rows[Rowindex].Cells[1].FindControl("txtAmount");

                Total += Convert.ToInt32( txtFeesAmount.Text);
                tostring= Total.ToString();
                tostring = ((TextBox)gvSales.FooterRow.FindControl("txtTotal")).Text;

            }
        }
    }


}

The values in the taxtbox are added and while display in footer template it is not assinging with the added value. it gives me error:

object referrence not set to instance of object.

How to assign the value(total values added from each textbox) to the'txtTotal' Textbox in gridview

i.e in this line

tostring = ((TextBox)gvSales.FooterRow.FindControl("txtTotal")).Text;

+1  A: 

do like this :

grdList.Columns[2].FooterText = sumDebit.ToString();
masoud ramezani
ya it works out, but im not getting the value displayed in total textbox
Ranjana