//add new row
    private void SetInitialRow()
    {
        DataTable dt = new DataTable();
        DataRow   dr = null;

        //Define the Columns
        dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Column0", typeof(string)));
        dt.Columns.Add(new DataColumn("Column1", typeof(string)));
        dt.Columns.Add(new DataColumn("Column2", typeof(string)));
        dt.Columns.Add(new DataColumn("Column3", typeof(string)));
        dt.Columns.Add(new DataColumn("Column4", typeof(string)));
        dt.Columns.Add(new DataColumn("Column5", typeof(string)));
        dt.Columns.Add(new DataColumn("Column6", typeof(string)));
        dt.Columns.Add(new DataColumn("Column7", typeof(string)));

        //Add a Dummy Data on Initial Load
        dr = dt.NewRow();
        dr["RowNumber"] = 1;
        dt.Rows.Add(dr);

        //Store the DataTable in ViewState
        ViewState["CurrentTable"] = dt;
        //Bind the DataTable to the Grid
        GridViewpo.DataSource = dt;
        GridViewpo.DataBind();

        //Extract and Fill the DropDownList with Data
        //DropDownList ddlItem = (DropDownList)GridViewpo.Rows[0].Cells[2].FindControl("ddlItem");
        //FillDropDownList(ddlItem);
    }
    private void AddNewRowToGrid()
    {
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow   drCurrentRow   = null;

            if (dtCurrentTable.Rows.Count > 0)
            {
                drCurrentRow = dtCurrentTable.NewRow();
                drCurrentRow["RowNumber"] = dtCurrentTable.Rows.Count + 1;
                //add new row to DataTable
                dtCurrentTable.Rows.Add(drCurrentRow);
                //Store the current data to ViewState
                ViewState["CurrentTable"] = dtCurrentTable;

                for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++)
                {
                    TextBox txtBatch  = (TextBox)GridViewpo.Rows[i].Cells[0].FindControl("txtBatch");
                    TextBox txtShade  = (TextBox)GridViewpo.Rows[i].Cells[1].FindControl("txtShade");
                    TextBox txtRoll   = (TextBox)GridViewpo.Rows[i].Cells[2].FindControl("txtRoll");
                    TextBox txtKg     = (TextBox)GridViewpo.Rows[i].Cells[3].FindControl("txtKg");
                    TextBox txtMeter  = (TextBox)GridViewpo.Rows[i].Cells[4].FindControl("txtMeter");
                    TextBox txtPlies  = (TextBox)GridViewpo.Rows[i].Cells[5].FindControl("txtPlies");
                    TextBox txtActCut = (TextBox)GridViewpo.Rows[i].Cells[6].FindControl("txtActCut");
                    TextBox txtRej    = (TextBox)GridViewpo.Rows[i].Cells[6].FindControl("txtRej");


                    // Update the DataRow with the DDL Selected Items
                    dtCurrentTable.Rows[i]["Column0"] = txtBatch.Text;
                    dtCurrentTable.Rows[i]["Column1"] = txtShade.Text;
                    dtCurrentTable.Rows[i]["Column2"] = txtRoll.Text;
                    dtCurrentTable.Rows[i]["Column3"] = txtKg.Text;
                    dtCurrentTable.Rows[i]["Column4"] = txtMeter.Text;
                    dtCurrentTable.Rows[i]["Column5"] = txtPlies.Text;
                    dtCurrentTable.Rows[i]["Column6"] = txtActCut.Text;
                    dtCurrentTable.Rows[i]["Column7"] = txtRej.Text;
                    //dtCurrentTable.Rows[i]["Column2"] = ddlItem.SelectedItem.Text;
                    //For Smv
                }
                //Rebind the Grid with the current data
                GridViewpo.DataSource = dtCurrentTable;
                GridViewpo.DataBind();
            }
        }
        else
        {
            Response.Write("ViewState is null");
        }
        //Set Previous Data on Postbacks
        SetPreviousData();
    }
示例#3
0
    private void AddNewRowToGrid()
    {
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow   drCurrentRow   = null;

            if (dtCurrentTable.Rows.Count > 0)
            {
                drCurrentRow = dtCurrentTable.NewRow();
                drCurrentRow["RowNumber"] = dtCurrentTable.Rows.Count + 1;
                //add new row to DataTable
                dtCurrentTable.Rows.Add(drCurrentRow);
                //Store the current data to ViewState
                ViewState["CurrentTable"] = dtCurrentTable;

                for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++)
                {
                    TextBox txtArt = (TextBox)GridViewpo.Rows[i].Cells[0].FindControl("txtArt");
                    TextBox txtQty = (TextBox)GridViewpo.Rows[i].Cells[1].FindControl("txtQty");

                    //extract the DropDownList Selected Items
                    DropDownList ddlItem = (DropDownList)GridViewpo.Rows[i].Cells[2].FindControl("ddlItem");
                    //For Smv
                    TextBox txtSmv = (TextBox)GridViewpo.Rows[i].Cells[3].FindControl("txtSmv");

                    // Update the DataRow with the DDL Selected Items
                    dtCurrentTable.Rows[i]["Column0"] = txtArt.Text;
                    dtCurrentTable.Rows[i]["Column1"] = txtQty.Text;
                    //dtCurrentTable.Rows[i]["Column2"] = txtprc.Text;
                    //dtCurrentTable.Rows[i]["Column3"] = txtspdt.Text;
                    //dtCurrentTable.Rows[i]["Column4"] = txtexft.Text;
                    //dtCurrentTable.Rows[i]["Column5"] = txtld.Text;
                    //dtCurrentTable.Rows[i]["Column6"] = txtbss.Text;
                    dtCurrentTable.Rows[i]["Column2"] = ddlItem.SelectedItem.Text;
                    //For Smv
                    dtCurrentTable.Rows[i]["Column3"] = txtSmv.Text;
                }
                //Rebind the Grid with the current data
                GridViewpo.DataSource = dtCurrentTable;
                GridViewpo.DataBind();
            }
        }
        else
        {
            Response.Write("ViewState is null");
        }
        //Set Previous Data on Postbacks
        SetPreviousData();
    }