private void SetInitRow()
        {
            DataTable dt = new DataTable();
            DataRow   dr = null;

            //dt.Columns.Add(new DataColumn("ITEMCODE", typeof(string)));
            dt.Columns.Add(new DataColumn("ITEMNAME", typeof(string)));
            dt.Columns.Add(new DataColumn("ITEM TYPE", typeof(string)));
            dt.Columns.Add(new DataColumn("UNITS", typeof(string)));
            dt.Columns.Add(new DataColumn("RETAILPRICE", typeof(string)));
            dt.Columns.Add(new DataColumn("PACKINGSIZE", typeof(string)));

            dr = dt.NewRow();

            //dr["ITEMCODE"] = string.Empty;
            dr["ITEMNAME"]    = string.Empty;
            dr["ITEM TYPE"]   = string.Empty;
            dr["UNITS"]       = string.Empty;
            dr["RETAILPRICE"] = string.Empty;
            dr["PACKINGSIZE"] = string.Empty;

            dt.Rows.Add(dr);

            //Store the DataTable in ViewState
            ViewState["dt_adItm"] = dt;

            GVPro.DataSource = dt;
            GVPro.DataBind();
        }
        private void AddNewRow()
        {
            int rowIndex = 0;

            if (ViewState["dt_adItm"] != null)
            {
                DataTable dt    = (DataTable)ViewState["dt_adItm"];
                DataRow   drRow = null;
                if (dt.Rows.Count > 0)
                {
                    for (int i = 1; i <= dt.Rows.Count; i++)
                    {
                        //extract the Controls values

                        TextBox      TBItmNam      = (TextBox)GVPro.Rows[rowIndex].Cells[0].FindControl("TBItmNam");
                        DropDownList DDL_Itmtyp    = (DropDownList)GVPro.Rows[rowIndex].Cells[1].FindControl("DDL_Itmtyp");
                        DropDownList DDL_Unt       = (DropDownList)GVPro.Rows[rowIndex].Cells[2].FindControl("DDL_Unt");
                        TextBox      TBPurPrc      = (TextBox)GVPro.Rows[rowIndex].Cells[3].FindControl("TBPurPrc");
                        TextBox      TBSalPrc      = (TextBox)GVPro.Rows[rowIndex].Cells[3].FindControl("TBSalPrc");
                        TextBox      TBRtlPrc      = (TextBox)GVPro.Rows[rowIndex].Cells[3].FindControl("TBRtlPrc");
                        TextBox      TBpksiz       = (TextBox)GVPro.Rows[rowIndex].Cells[4].FindControl("TBpksiz");
                        TextBox      PACKINCARTONS = (TextBox)GVPro.Rows[rowIndex].Cells[5].FindControl("TBcartsiz");

                        drRow = dt.NewRow();

                        //dt.Rows[i - 1]["ITEMCODE"] = DDL_Unt.Text;
                        dt.Rows[i - 1]["ITEMNAME"]      = TBItmNam.Text;
                        dt.Rows[i - 1]["ITEM TYPE"]     = DDL_Itmtyp.Text;
                        dt.Rows[i - 1]["UNITS"]         = DDL_Unt.Text;
                        dt.Rows[i - 1]["PURCHASEPRICE"] = TBPurPrc.Text;
                        dt.Rows[i - 1]["SALEPRICE"]     = TBSalPrc.Text;
                        //dt.Rows[i - 1]["RETAILPRICE"] = TBRtlPrc.Text;
                        dt.Rows[i - 1]["PACKINGSIZE"]   = TBpksiz.Text;
                        dt.Rows[i - 1]["PACKINCARTONS"] = PACKINCARTONS.Text;
                        rowIndex++;

                        DDL_Unt.Focus();
                    }
                    dt.Rows.Add(drRow);
                    ViewState["dt_adItm"] = dt;

                    GVPro.DataSource = dt;
                    GVPro.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreRow();
        }
        protected void GVPro_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (ViewState["dt_adItm"] != null)
            {
                DataTable dt           = (DataTable)ViewState["dt_adItm"];
                DataRow   drCurrentRow = null;
                int       rowIndex     = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow          = dt.NewRow();
                    ViewState["dt_adItm"] = dt;

                    GVPro.DataSource = dt;
                    GVPro.DataBind();

                    SetPreRow();
                    //ptnSno();
                }
            }
        }