开发者

Assign a value to special footer column in Gridview

I have a Gridview like this;

Assign a value to special footer column in Gridview

In my .cs file i calculate value of BV, MV, KV total value with this code and i assign to a Label. Labels are under the Gridview.开发者_StackOverflow社区 BUT, some customer names long some of short, because of that, labels location changing according to Gridview. Because of that i don't want use Label.

I calculate a value with this code, and how can i assing BV, MV and KV columns footer this value?

double sumRISK = 0;
            foreach (GridViewRow gvr in GridView1.Rows)
            {
                CheckBox cb = (CheckBox)gvr.FindControl("NameCheckBoxField1");
                if (cb.Checked == true)
                {
                    double amountBV = Convert.ToDouble(gvr.Cells[7].Text);
                    if (amountBV != -1)
                    {
                        sumRISK += amountBV;
                    }
                }
            }
            RISK_Label.Text = String.Format("{0:n}", sumRISK);


You should be able to set the FooterRow like below

GridView1.FooterRow.Cells[0].Text = SumRISK.ToString();

Here is a small working example using the same way of summarizing as you.

        int[] values = {1,3,6};

        GridView1.DataSource = values;
        GridView1.DataBind();

        int total = 0;

        foreach (GridViewRow item in GridView1.Rows)
        {
            total += Convert.ToInt32(item.Cells[0].Text);
        }

        GridView1.FooterRow.Cells[0].Text = total.ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜