protected void Button1_Click(object sender, EventArgs e) { DDL.Focus(); int tempqnty = Convert.ToInt32(qntyTxt.Text); int tempStock = Convert.ToInt32(ViewState["tempStock"]); if (qntyTxt.Text != "" && tempqnty <= tempStock && availTxt.Text != "" && priceTxt.Text != "" && discTxt.Text != "" && Convert.ToInt32(availTxt.Text) != 0) { dt.Columns.Add("Sr#"); dt.Columns.Add("Id"); dt.Columns.Add("Item"); dt.Columns.Add("Qnty"); dt.Columns.Add("Rt"); dt.Columns.Add("Price"); DataRow dr = null; if (GridView1.Rows.Count == 0) { ViewState["emp"] = null; } if (ViewState["emp"] != null) { for (int i = 0; i < 1; i++) { dt = (DataTable)ViewState["emp"]; if (dt.Rows.Count > 0) { dr = dt.NewRow(); dr["Sr#"] = dt.Rows.Count + 1;; dr["Id"] = DDL.SelectedItem.Value; dr["Item"] = DDL.SelectedItem.Text; dr["Qnty"] = qntyTxt.Text; dr["Rt"] = priceTxt.Text; dr["Price"] = Label1.Text; dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); } } } else { dr = dt.NewRow(); dr["Sr#"] = dt.Rows.Count + 1;; dr["Id"] = DDL.SelectedItem.Value; dr["Item"] = DDL.SelectedItem.Text; dr["Qnty"] = qntyTxt.Text; dr["Rt"] = priceTxt.Text; dr["Price"] = Label1.Text; dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); } ViewState["emp"] = dt; updated_grandTotal(); // ViewState["gt"] = Convert.ToInt32(ViewState["gt"]) + Convert.ToInt32(Label1.Text); // grandTotal = grandTotal + Convert.ToInt32(Label1.Text); Label2.Text = "G-Total :" + ViewState["gt"].ToString(); reset_item_btn(); Asucc.Visible = true; } else { Asucc.Visible = false; Afail.Visible = true; } }