protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Session["login_id"] == null) { Response.Redirect("Login.aspx"); return; } DataTable dt = new DataTable(); DataTable dt2 = new DataTable(); using (conn) { SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM snacks WHERE item_status = 1", conn); ad.Fill(dt); ad = new SqlDataAdapter("SELECT category FROM snacks WHERE item_status = 1 GROUP BY category", conn); ad.Fill(dt2); } SnackList.DataSource = dt; SnackList.DataBind(); ddlCategory.DataSource = dt2; ddlCategory.DataBind(); } }
public void BuySnacks(string name) { var obj = SnackList.FirstOrDefault(x => x.Name.ToLower() == name); Console.WriteLine(obj); int price = obj.Price; priceList.Add(price); }
protected void btnShowAll_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); using (conn) { SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM snacks WHERE item_status = 1", conn); ad.Fill(dt); } SnackList.DataSource = dt; SnackList.DataBind(); }
protected void btnFilter_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); using (conn) { SqlDataAdapter ad = new SqlDataAdapter(string.Format("SELECT * FROM snacks WHERE item_status = 1 AND category LIKE '{0}'", ddlCategory.SelectedItem.Value.ToString()), conn); ad.Fill(dt); } SnackList.DataSource = dt; SnackList.DataBind(); }