//Method used when the page is intially called and loaded private void Binding() { //Sets the datasource of the webpage's Gridview to the TableBase object's returned DataView PurchaseOrderLinesGridView.DataSource = Base.BindGrid(); //Calls for the page to be updated and a postback PurchaseOrderLinesGridView.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { HttpCookie cookie = Request.Cookies["userInfo"]; if (Request.Cookies["userInfo"] == null) { Response.Redirect("login.aspx"); } else { nameLabel.Text = Request.Cookies["userInfo"]["firstName"]; if (Request.Cookies["userInfo"]["admin"] == "True") //Checks to see if the user is an admin or not and enables related department and employee items to be shown { addEmployeeModal.Visible = true; addDepartmentModal.Visible = true; departmentnav.Visible = true; employeenav.Visible = true; blockopenemployees.Visible = true; opendepartmodal.Visible = true; openemployeemodal.Visible = true; } cookie.Expires = DateTime.Now.AddMinutes(10); Response.Cookies.Set(cookie); } if (!Page.IsPostBack) { DropDownPop(); //Creates default TableBase object based on target view/table and Default sorting column Base = new TableBase("RecentPurchaseOrders", "DateOrdered"); //Binds the default data to ViewState in order to keep throughout postbacks ViewState["Table"] = Base; //Initial binding and loading of data onto table this.Binding(); //Creates default TableBase object based on target view/table and Default sorting column BaseItem = new TableBase("AddItem", "SKU"); //Binds the default data to ViewState in order to keep throughout postbacks ViewState["ItemTable"] = BaseItem; //New Mepty datatable is created to store data of temporary purchase order dt = new DataTable(); //Columns are added to new datatable with appropriate names dt.Columns.AddRange(new DataColumn[5] { new DataColumn("SKU", typeof(string)), new DataColumn("ItemName", typeof(string)), new DataColumn("SupplierID", typeof(string)), new DataColumn("Quantity", typeof(int)), new DataColumn("Price", typeof(decimal)) }); ViewState["ordertable"] = dt; //Initial binding and loading of data onto table GridViewItem.DataSource = BaseItem.BindGrid(); GridViewItem.DataBind(); OrderBinding(); ModalIDPop(); } else //All consecutive refreshes/postbacks will update the ViewState key with new recurring data. { Base = (TableBase)ViewState["Table"]; BaseItem = (TableBase)ViewState["ItemTable"]; //BaseOrder = (TableBase)ViewState["OrderTable"]; dt = ViewState["ordertable"] as DataTable; OrderBinding(); if (GridViewItem.SelectedRow != null) //Checks to see if there are any selected rows during a postback { AddItemButton.Enabled = true; } else { AddItemButton.Enabled = false; } } TotalPrice(); }