protected void LinkButton1_Click(object sender, EventArgs e) { string dir = ""; try { if (FileUpload1.HasFile) { dir = Server.MapPath("/images/indexpicture/"); if (File.Exists(dir + FileUpload1.FileName)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('文件已存在!')", true); return; } FileUpload1.SaveAs(dir + FileUpload1.FileName); } else { Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('请选择要上传的文件!')", true); return; } Place p = new Place(); p.Places = txtPlace.Text; p.Image = "/indexpicture/" + FileUpload1.FileName; PlaceBLL bll = new PlaceBLL(); bll.AddPlace(p); Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('数据提交成功!')", true); txtPlace.Text = ""; } catch (Exception ee) { Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('数据提交失败!')", true); } }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { PlaceBLL bll = new PlaceBLL(); string sql = "select top 6 * from Place order by PlaceID"; DataSet ds = bll.getPlace(sql); DataList1.DataSource = ds.Tables[0]; DataList1.DataBind(); } }