protected void LoginBtn_Click(object sender, EventArgs e) { if (Page.IsValid) { string username = Login_Username.Text; string password = Login_Password.Text; SqlDataSource1.SelectParameters["Username"].DefaultValue = username; SqlDataSource1.SelectParameters["Password"].DefaultValue = password; SqlDataSource1.DataSourceMode = SqlDataSourceMode.DataReader; SqlDataReader reader = (SqlDataReader)SqlDataSource1.Select(DataSourceSelectArguments.Empty); if (reader.HasRows) { reader.Read(); Session["Username"] = reader["Username"].ToString(); Session["Password"] = reader["Password"].ToString(); Session["isLogin"] = 1; } SqlDataSource1.Dispose(); if (Login_RememberUsernameChkbox.Checked) { Session["RememberUsername"] = "******"; } if (Session["isLogin"] != null) { Response.Redirect("~/Commodity.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["cart"] == null) { Session["cart"] = new Dictionary <String, int>(); } Dictionary <String, int> cart = (Dictionary <String, int>)Session["cart"]; if (Request.RequestType == "POST") { cart.Remove(Request.Form["id"]); Session["cart"] = cart; return; } if (cart.Count != 0) { String cartId = "(" + string.Join(",", cart.Keys) + ")"; SqlDataSource1.SelectCommand = "SELECT * FROM [products] WHERE [id] in " + cartId; Repeater1.DataBind(); } else { Repeater1.Dispose(); SqlDataSource1.Dispose(); } }