private void ReportGrid(string FromDate, string ToDate, string StrCondition)
    {
        try
        {
            DsDeviationGrd = Obj_Deviation.ShowStockInHand(FromDate, ToDate, StrCondition, out StrError);

            if (DsDeviationGrd.Tables.Count > 0 && DsDeviationGrd.Tables[0].Rows.Count > 0)
            {
                DeviationGrid.DataSource = DsDeviationGrd.Tables[0];
                DeviationGrid.DataBind();
                DeviationGrid.Columns[13].Visible = false;
                DeviationGrid.Columns[14].Visible = false;
                //GetAmount();
                ((TextBox)DeviationGrid.Rows[0].FindControl("GrtxtPhyClosing")).Focus();
            }

            else
            {
                DeviationGrid.DataSource = null;
                DeviationGrid.DataBind();
                SetInitialRow();
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
    private void SetInitialRow()
    {
        try
        {
            DataTable dt = new DataTable();
            DataRow   dr = null;
            dt.Columns.Add(new DataColumn("#", typeof(Int32)));
            dt.Columns.Add(new DataColumn("Category", typeof(string)));
            dt.Columns.Add(new DataColumn("Code", typeof(string)));
            dt.Columns.Add(new DataColumn("Product", typeof(string)));
            dt.Columns.Add(new DataColumn("UnitID", typeof(Int32)));
            dt.Columns.Add(new DataColumn("Unit", typeof(string)));
            dt.Columns.Add(new DataColumn("MRP", typeof(decimal)));
            dt.Columns.Add(new DataColumn("LocationID", typeof(Int32)));
            dt.Columns.Add(new DataColumn("Location", typeof(string)));
            dt.Columns.Add(new DataColumn("Closing", typeof(decimal)));
            dt.Columns.Add(new DataColumn("SystemAmount", typeof(decimal)));
            dt.Columns.Add(new DataColumn("PhyClosing", typeof(decimal)));
            dt.Columns.Add(new DataColumn("Deviation", typeof(decimal)));
            dt.Columns.Add(new DataColumn("DeviationAmount", typeof(decimal)));
            dt.Columns.Add(new DataColumn("PhyAmount", typeof(decimal)));
            dt.Columns.Add(new DataColumn("PhyDeviationQty", typeof(decimal)));
            dt.Columns.Add(new DataColumn("PhyDeviationAmt", typeof(decimal)));
            dt.Columns.Add(new DataColumn("PhyDeviationAmount", typeof(decimal)));

            dr = dt.NewRow();

            dr["#"]                  = 0;
            dr["Category"]           = "";
            dr["Code"]               = "";
            dr["Product"]            = "";
            dr["UnitID"]             = 0;
            dr["Unit"]               = "";
            dr["MRP"]                = 0;
            dr["LocationID"]         = 0;
            dr["Location"]           = "";
            dr["Closing"]            = 0;
            dr["SystemAmount"]       = 0;
            dr["PhyClosing"]         = 0;
            dr["Deviation"]          = 0;
            dr["DeviationAmount"]    = 0;
            dr["PhyAmount"]          = 0;
            dr["PhyDeviationQty"]    = 0;
            dr["PhyDeviationAmt"]    = 0;
            dr["PhyDeviationAmount"] = 0;

            dt.Rows.Add(dr);
            ViewState["CurrentTable"] = dt;
            DeviationGrid.DataSource  = dt;
            DeviationGrid.DataBind();
            dt = null;
            dr = null;
            DeviationGrid.Columns[13].Visible = false;
            DeviationGrid.Columns[14].Visible = false;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
    protected void ReportGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            switch (e.CommandName)
            {
            case ("Select"):
            {
                if (Convert.ToInt32(e.CommandArgument) != 0)
                {
                    ViewState["ID"] = Convert.ToInt32(e.CommandArgument);
                    Ds = Obj_Deviation.GetRecordForEdit(Convert.ToInt32(e.CommandArgument), out StrError);

                    if (Ds.Tables[0].Rows.Count > 0)
                    {
                        DeviationGrid.DataSource = Ds.Tables[0];
                        DeviationGrid.DataBind();
                        ViewState["CurrentTable"] = Ds.Tables[0];
                        BtnUpdate.Visible         = true;
                        BtnSave.Visible           = false;
                        BtnShow.Visible           = false;
                        lblDevationPeriod.Text    = "Deviation Period - " + Ds.Tables[0].Rows[0]["DevationPeriod"].ToString();
                        MakeControlDisable(1);
                        DeviationGrid.Columns[13].Visible = false;
                        DeviationGrid.Columns[14].Visible = false;
                        (TxtSysamount.Text)          = Ds.Tables[0].Rows[0]["SysAmt"].ToString();
                        (TxtPhyamount.Text)          = Ds.Tables[0].Rows[0]["PhyAmt"].ToString();
                        (TxtTotDeviationAmount.Text) = (Convert.ToDecimal((TxtSysamount.Text)) - Convert.ToDecimal((TxtPhyamount.Text))).ToString("#0.00");
                        // GetAmount();
                        ScriptManager.RegisterStartupScript(this, GetType(), "TotalForUpdates", "javascript:TotalForUpdates();", true);
                    }
                    else
                    {
                        MakeEmptyForm();
                    }

                    Ds            = null;
                    Obj_Deviation = null;
                }
                break;
            }
            }
        }
        catch (Exception ex) { throw new Exception(ex.Message); }
    }