如何将值(从每个文本框添加的总值)分配给gridview中的“txtTotal”文本框

时间:2010-03-02 07:24:02

标签: c# asp.net gridview

我有一个gridview

                                                                           '/>                                                                   总计的                                                                                                                                                                                                                                    

我的代码背后:

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;

            }
        }
    }


}

添加了taxtbox中的值,并且在页脚模板中显示时,它不会添加附加值。 它给了我错误:

对象引用未设置为对象的实例。

如何将值(从每个文本框添加的总值)分配到gridview中的'textTotal'文本框

即在这一行

tostring =((TextBox)gvSales.FooterRow.FindControl(“txtTotal”))。Text;

1 个答案:

答案 0 :(得分:0)

这样做:

grdList.Columns[2].FooterText = sumDebit.ToString();