protected void FV_shopInfo_ItemUpdating(object sender, FormViewUpdateEventArgs e) { // Get tất cả các field DataKey id = FV_shopInfo.DataKey; TextBox wf_locate = (TextBox)FV_shopInfo.FindControl("wf_locate"); TextBox wf_hotLine = (TextBox)FV_shopInfo.FindControl("wf_hotLine"); TextBox wf_website = (TextBox)FV_shopInfo.FindControl("wf_website"); TextBox wf_email = (TextBox)FV_shopInfo.FindControl("wf_email"); TextBox wf_openTime = (TextBox)FV_shopInfo.FindControl("wf_openTime"); TextBox wf_openDates = (TextBox)FV_shopInfo.FindControl("wf_openDates"); TextBox wf_fb = (TextBox)FV_shopInfo.FindControl("wf_fb"); TextBox wf_ytb = (TextBox)FV_shopInfo.FindControl("wf_ytb"); TextBox wf_maps = (TextBox)FV_shopInfo.FindControl("wf_maps"); FileUpload wf_images = (FileUpload)FV_shopInfo.FindControl("wf_images"); string imgPath = wf_images.FileName != "" ? "/backend/assets/images/" + System.IO.Path.GetFileNameWithoutExtension(wf_images.FileName) + "-" + DateTime.Now.ToString("ddMMyyyyhhmmss") + System.IO.Path.GetExtension(wf_images.FileName) : ""; try { ShopInfo s = new ShopInfo( int.Parse(id.Value.ToString()) , wf_locate.Text.Trim() , wf_hotLine.Text.Trim() , wf_website.Text.Trim() , wf_email.Text.Trim() , wf_openTime.Text.Trim() , wf_openDates.Text.Trim() , wf_fb.Text.Trim() , wf_ytb.Text.Trim() , wf_maps.Text.Trim() , imgPath ); // Nếu cập nahajt thành công if (b.UpdateShopInfo(s)) { // Nếu người dùng up ảnh thì up lên server if (imgPath != "") { imgPath = AppDomain.CurrentDomain.BaseDirectory + imgPath; wf_images.PostedFile.SaveAs(imgPath); } bigTopConnerAlert("Đã cập nhật thành công"); // back to default view FV_shopInfo.ChangeMode(FormViewMode.ReadOnly); this.fetchDataToShopInfoFormView(); } } catch (Exception ex) { this.errorAlert(ex.Message); } }
protected void fetchDataToShopInfoFormView() { try { List <ShopInfo> lstShop = b.GetShopInfo(); FV_shopInfo.DataSource = lstShop; FV_shopInfo.DataBind(); } catch (Exception e) { errorAlert(e.Message); } }
// Các chế độ xem thay đổi ví dụ: thêm sửa protected void FV_shopInfo_ModeChanging(object sender, FormViewModeEventArgs e) { FV_shopInfo.ChangeMode(e.NewMode); this.fetchDataToShopInfoFormView(); }