登陆成功后,返回登陆前的网址
登陆前网站的cs的Page_Load方法中加入:
protected void Page_Load(object sender, EventArgs e) { Session.Add("url", Request.Url.ToString()); }
登录网站的cs登录成功后:
Response.Redirect(Session["url"].ToString());
删除服务器图片
GridView1绑定数据库删除图片例子:
cs文件:
绑定数据库:
private string connStr = ConfigurationManager.ConnectionStrings["qiyesql"].ConnectionString;
删除服务器图片:
protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e) { SqlConnection con = new SqlConnection(connStr); con.Open(); SqlCommand com = new SqlCommand("select image from huandengyi where id=‘" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "‘", con); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { string path = HttpContext.Current.Server.MapPath("~/" + dr["image"].ToString()); if (File.Exists(path)) { File.Delete(path); } else { Response.Write("<script>alert(‘图片不存在或已删除‘);</script>"); } } else { Response.Write("<script>alert(‘数据错误‘);</script>"); } }
aspx GridView1里加入属性
OnRowDeleting="GridView1_RowDeleting1"
时间: 2024-10-25 00:46:40