protected void Page_Load(object sender, EventArgs e) { if ((List <Vehicle>)Session["data"] == null) // Is new Session { vehicleList = new List <Vehicle>(); this.Session["data"] = vehicleList; } else // Old Session { vehicleList = (List <Vehicle>)Session["data"]; } VehicleGridView.DataSource = (List <Vehicle>)Session["data"]; // Set GridView DataSource VehicleGridView.DataBind(); // Bind/Update GridView }
protected void AddBtn_Click(object sender, EventArgs e) { //The page will submit the form data to the server, which will create a new Car or Motorcycle object and store the new object in a data structure of type: List<Vehicle>. if (DropDownList1.SelectedIndex == 1) { vehicleList.Add(new Car(MakeTxtBox.Text, ModelTxtBox.Text, ColorTxtBox.Text, InteriorRadioBtn.Text, int.Parse(NumDoorsTxtBox.Text))); } else if (DropDownList1.SelectedIndex == 2) { vehicleList.Add(new Motorcycle(MakeTxtBox.Text, ModelTxtBox.Text, ColorTxtBox.Text)); } VehicleGridView.DataBind(); }
protected void Bind() { using (MySqlConnection con = new MySqlConnection(cString)) { using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM VEHICLE")) { using (MySqlDataAdapter da = new MySqlDataAdapter()) { cmd.Connection = con; da.SelectCommand = cmd; using (DataTable dt = new DataTable()) { da.Fill(dt); VehicleGridView.DataSource = dt; VehicleGridView.DataBind(); } } } } }
protected void page_load(object sender, EventArgs e) { if (Session["Logged"].Equals("Yes") && Session["IS_ADMIN"].Equals("true")) { if (!this.IsPostBack) { try { using (MySqlConnection con = new MySqlConnection(cString)) { using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM SOLD_VEHICLES")) { using (MySqlDataAdapter da = new MySqlDataAdapter()) { cmd.Connection = con; da.SelectCommand = cmd; using (DataTable dt = new DataTable()) { da.Fill(dt); VehicleGridView.DataSource = dt; VehicleGridView.DataBind(); } } } } } catch (MySqlException ex) { msgTxt.ForeColor = System.Drawing.Color.Red; msgTxt.Text = "Sold Inventory could not be displayed; refer to below error message:" + "<br />" + ex.ToString(); } } } else { Response.Redirect("~/sign_in.aspx"); } }