Exemplo n.º 1
0
        private void SetInitRowReq()
        {
            DataTable dt = new DataTable();
            DataRow   dr = null;

            dt.Columns.Add(new DataColumn("PRODUCTS", typeof(string)));
            dt.Columns.Add(new DataColumn("QUANTITY", typeof(string)));
            dt.Columns.Add(new DataColumn("RATE", typeof(string)));
            dt.Columns.Add(new DataColumn("AMOUNT", typeof(string)));
            dt.Columns.Add(new DataColumn("NARRATION", typeof(string)));

            dr              = dt.NewRow();
            dr["PRODUCTS"]  = string.Empty;
            dr["QUANTITY"]  = string.Empty;
            dr["RATE"]      = string.Empty;
            dr["AMOUNT"]    = string.Empty;
            dr["NARRATION"] = string.Empty;

            dt.Rows.Add(dr);

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

            GVDetReq.DataSource = dt;
            GVDetReq.DataBind();
        }
Exemplo n.º 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 DDLPro   = (DropDownList)GVDetReq.Rows[rowIndex].Cells[0].FindControl("DDL_Pro");
                        TextBox      TBProQty = (TextBox)GVDetReq.Rows[rowIndex].Cells[1].FindControl("TBProQty");
                        TextBox      TBProrat = (TextBox)GVDetReq.Rows[rowIndex].Cells[2].FindControl("TBProrat");
                        TextBox      TBAmt    = (TextBox)GVDetReq.Rows[rowIndex].Cells[3].FindControl("TBAmt");
                        TextBox      TBNarr   = (TextBox)GVDetReq.Rows[rowIndex].Cells[4].FindControl("TBNarr");

                        drRow = dt.NewRow();

                        dt.Rows[i - 1]["PRODUCTS"]  = DDLPro.Text;
                        dt.Rows[i - 1]["QUANTITY"]  = TBProQty.Text;
                        dt.Rows[i - 1]["RATE"]      = TBProrat.Text;
                        dt.Rows[i - 1]["AMOUNT"]    = TBAmt.Text;
                        dt.Rows[i - 1]["NARRATION"] = TBNarr.Text;

                        rowIndex++;

                        float GTotal = 0;
                        for (int j = 0; j < GVDetReq.Rows.Count; j++)
                        {
                            TextBox total = (TextBox)GVDetReq.Rows[j].FindControl("TBAmt");
                            //GTotal = Convert.ToSingle(TbAddPurNetTtl.Text);
                            GTotal += Convert.ToSingle(total.Text);
                        }
                        TBGrssTotal.Text = GTotal.ToString();
                    }
                    dt.Rows.Add(drRow);
                    ViewState["dt_adItm"] = dt;

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

            //Set Previous Data on Postbacks
            SetPreRowReq();
        }