Click here to Skip to main content
15,885,998 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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();
    }
}
Posted
Comments
MaroofQaiser 20-May-15 3:56am    
i have found the solution, and it works perfectly, here is my code

1 solution

C#
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();
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900