示例#1
0
        private void SetInitRowitm()
        {
            DataTable dt = new DataTable();
            DataRow   dr = null;

            dt.Columns.Add(new DataColumn("ITEMS", typeof(string)));
            dt.Columns.Add(new DataColumn("DESCRIPTIONS", typeof(string)));
            dt.Columns.Add(new DataColumn("QTY", typeof(string)));
            dt.Columns.Add(new DataColumn("UNIT", typeof(string)));
            dt.Columns.Add(new DataColumn("REMARKS", typeof(string)));

            dr = dt.NewRow();

            dr["ITEMS"]        = string.Empty;
            dr["DESCRIPTIONS"] = string.Empty;
            dr["QTY"]          = string.Empty;
            dr["UNIT"]         = string.Empty;
            dr["REMARKS"]      = string.Empty;

            dt.Rows.Add(dr);

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

            GVCNItm.DataSource = dt;
            GVCNItm.DataBind();
        }
示例#2
0
        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 TextBox values
                        DropDownList ddl_Itm            = (DropDownList)GVCNItm.Rows[rowIndex].Cells[0].FindControl("ddl_Itm");
                        TextBox      TbaddPurItmDscptin = (TextBox)GVCNItm.Rows[rowIndex].Cells[1].FindControl("TbaddPurItmDscptin");
                        TextBox      TbAddPurItmQty     = (TextBox)GVCNItm.Rows[rowIndex].Cells[2].FindControl("TbAddPurItmQty");
                        TextBox      TbAddPurUnit       = (TextBox)GVCNItm.Rows[rowIndex].Cells[3].FindControl("TbAddPurUnit");
                        TextBox      TBDCNRmk           = (TextBox)GVCNItm.Rows[rowIndex].Cells[4].FindControl("TBDCNRmk");


                        drRow = dt.NewRow();

                        dt.Rows[i - 1]["ITEMS"]        = ddl_Itm.SelectedValue;
                        dt.Rows[i - 1]["DESCRIPTIONS"] = TbaddPurItmDscptin.Text;
                        dt.Rows[i - 1]["QTY"]          = TbAddPurItmQty.Text;
                        dt.Rows[i - 1]["UNIT"]         = TbAddPurUnit.Text;
                        dt.Rows[i - 1]["REMARKS"]      = TBDCNRmk.Text;


                        rowIndex++;

                        ddl_Itm.Focus();
                    }

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

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

            //Set Previous Data on Postbacks
            SetPreRowitm();
        }
示例#3
0
        protected void GVCNItm_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;

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

                    SetPreRowitm();
                }
            }
        }