Пример #1
0
        private void FirstGridViewRow()
        {
            DataTable dt = new DataTable();

            if (dt.Columns.Count == 0)
            {
                dt.Columns.Add("Id", typeof(string));
                dt.Columns.Add("ProductName", typeof(string));
                dt.Columns.Add("Quantity", typeof(string));
            }

            DataRow NewRow = dt.NewRow();

            NewRow[0] = hdnTextBoxProductName.Value;
            NewRow[1] = TextBoxProductName.Text;
            NewRow[2] = TextBoxProductQuantity.Text;

            ViewState["Quantity"]   = TextBoxProductQuantity.Text;
            TextBoxProductName.Text = TextBoxProductQuantity.Text = "";
            Label1.Text             = ViewState["Quantity"].ToString();


            dt.Rows.Add(NewRow);
            ViewState["CurrentTable"]   = dt;
            GridViewShowData.DataSource = dt;
            GridViewShowData.DataBind();
        }
Пример #2
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            SqlConnection conn = da.getconnection();

            conn.Open();

            if (ViewState["CurrentTable"] != null)
            {
                string    QueryForOrder  = "INSERT INTO  [Order] VALUES(" + Convert.ToInt16(ViewState["Quantity"]) + ") SELECT SCOPE_IDENTITY()";
                var       cmd            = new SqlCommand(QueryForOrder, conn);
                int       ordId          = Convert.ToInt16(cmd.ExecuteScalar());
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
                foreach (DataRow row in dtCurrentTable.Rows)
                {
                    string id       = row[0].ToString();
                    string name     = row[1].ToString();
                    string quantity = row[2].ToString();

                    string QueryForOrdDetails = "INSERT INTO OrdDetails OUTPUT Inserted.Id VALUES(" + Convert.ToInt16(id) + "," + ordId + "," + Convert.ToInt16(quantity) + ")";

                    da.ExecuteQuery(QueryForOrdDetails, "ConnDB230");
                }
                ViewState["CurrentTable"]   = null;
                GridViewShowData.DataSource = null;
                GridViewShowData.DataBind();
            }
        }
Пример #3
0
        private void AddNewRow()
        {
            int rowIndex = 0;
            int x        = 0;

            if (ViewState["CurrentTable"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
                DataRow   drCurrentRow   = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        drCurrentRow    = dtCurrentTable.NewRow();
                        drCurrentRow[0] = hdnTextBoxProductName.Value;
                        drCurrentRow[1] = TextBoxProductName.Text;
                        drCurrentRow[2] = TextBoxProductQuantity.Text;

                        x = Convert.ToInt16(ViewState["Quantity"]) + Convert.ToInt16(TextBoxProductQuantity.Text);


                        rowIndex++;
                    }
                    ViewState["Quantity"] = x;
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable"] = dtCurrentTable;
                    Label1.Text                 = ViewState["Quantity"].ToString();
                    TextBoxProductName.Text     = TextBoxProductQuantity.Text = "";
                    GridViewShowData.DataSource = dtCurrentTable;
                    GridViewShowData.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
        }
Пример #4
0
 private void refresh()
 {
     GridViewShowData.DataSource = (DataTable)ViewState["CurrentTable"];
     GridViewShowData.DataBind();
 }