项目模板和编辑项目模板Gridview列总计并显示在页脚中 [英] Item Template and Edit Item Template Gridview Columns Total and show in Footer

查看:46
本文介绍了项目模板和编辑项目模板Gridview列总计并显示在页脚中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我一直在研究一个Gridview,它有ItemTemplate和EditItemTemplate,在这个Gridview中,我有一个用于网格更新行的编辑命令列,当它点击标签时将成为特定行的文本框,所以它非常难以同时添加标签和TExtbox的价值,这里是我的代码,请帮我解决这个问题,Thanx提前



Hello, I have been working on a Gridview, which have ItemTemplate and EditItemTemplate, In this Gridview, i have a Edit Command Column for Update Row of Grid, When it Clicks Labels will become Textboxes of specific row, so it is very difficult to add the value of labels and TExtbox at same time, here is my code, please help me about this trouble, Thanx in Advance

protected void GridColumnsTotal()
{
    foreach (GridViewRow gvr in GvGRN.Rows)
    {
        Label Opening = (Label)gvr.Cells[6].FindControl("lblOpening");
        TextBox Receiving =(TextBox)gvr.Cells[7].FindControl("Txtreceive");
        Label QtyRec = (Label)gvr.Cells[7].FindControl("lblReceive");
        Label Closing = (Label)gvr.Cells[8].FindControl("lblClosing");
        double Opn;
        double Rec;
        double Clo;
        double QRec;
        if (double.TryParse(Opening.Text.Trim(), out Opn))
        {
            total += Opn;
        }

        if (double.TryParse(Receiving.Text.Trim(), out Rec))
        {
            pay += Rec;
        }
        if (double.TryParse(QtyRec.Text.Trim(), out QRec))
        {
            QR += QRec;
        }
        if (double.TryParse(Closing.Text.Trim(), out Clo))
        {
            Tot += Clo;
        }
        GvGRN.FooterRow.Cells[6].Text = total.ToString();
        GvGRN.FooterRow.Cells[7].Text = (pay + QR).ToString();
        GvGRN.FooterRow.Cells[8].Text = Tot.ToString();
    }
}

推荐答案

protected void GridColumnsTotal()
        {
            for (var c = 0; c <= GvGRN.Rows.Count - 1; c++)
            {
                Label lblOpenig = (Label)GvGRN.Rows[c].FindControl("lblOpening");
                TextBox txtQ = (TextBox)GvGRN.Rows[c].FindControl("Txtreceive");
                Label lblQ = (Label)GvGRN.Rows[c].FindControl("lblReceive");
                Label Clois = (Label)GvGRN.Rows[c].FindControl("lblClosing");
                if (lblOpenig != null)
                {
                    total += Convert.ToDouble(lblOpenig.Text);
                }
                if (txtQ != null)
                {
                    pay += Convert.ToDouble(txtQ.Text);
                }
                if (lblQ != null)
                {
                    QR += Convert.ToDouble(lblQ.Text);
                }
                if (Clois != null)
                {
                    Tot += Convert.ToDouble(Clois.Text);
                }

                GvGRN.FooterRow.Cells[6].Text = total.ToString();
                GvGRN.FooterRow.Cells[7].Text = (pay + QR).ToString();
                GvGRN.FooterRow.Cells[8].Text = Tot.ToString();
            }
        }


这篇关于项目模板和编辑项目模板Gridview列总计并显示在页脚中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆