protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { string name = e.CommandName; int id = Convert.ToInt32(e.CommandArgument.ToString()); switch (name) { case "del": TinTuc_Info.Delete(id); Response.Redirect("admin.aspx?page=tintuc"); break; case "sua": TinTuc_Info tt = TinTuc_Info.getby_id(id); if (tt != null) { HiddenField_HinhAnh.Value = tt.HinhDaiDien; HiddenField_Id.Value = tt.id.ToString(); Label2.Text = "Sửa tin tức"; bntCapNhat.Text = "Cập Nhật"; e_image.ImageUrl = "../uploads/tintuc/" + tt.HinhDaiDien; txtTieuDe.Text = tt.TieuDe; txtTomTat.Text = tt.TomTat; txtNoiDung.Text = tt.NoiDung; e_image.Visible = true; MultiView1.ActiveViewIndex = 1; } break; } }
private void LoadData() { // Repeater1.DataSource = TinTuc_Info.getall(); //Repeater1.DataBind(); List <TinTuc_Info> list;; PagedDataSource objPds = new PagedDataSource(); list = TinTuc_Info.getall(); objPds.DataSource = list; objPds.AllowPaging = true; objPds.PageSize = 5;//số bài lặp trong 1 trang objPds.CurrentPageIndex = CurrentPage; Label2.Text = (CurrentPage + 1).ToString() + "\\" + objPds.PageCount.ToString(); //Disable tien va lui buttons bntTroLai.Enabled = !objPds.IsFirstPage; bntNext.Enabled = !objPds.IsLastPage; if (objPds.DataSourceCount == 0) { Label2.Text = "0"; bntNext.Visible = false; bntTroLai.Visible = false; } Repeater1.DataSource = objPds; Repeater1.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { id = Request.QueryString["id"].ToString(); tintuc = TinTuc_Info.getby_id(int.Parse(id)); Page.Title = tintuc.TieuDe; duongdan = Request.Url.ToString(); Repeater1.DataSource = TinTuc_Info.GetTop5(); Repeater1.DataBind(); }
protected void bntCapNhat_Click(object sender, EventArgs e) { if (bntCapNhat.Text == "Thêm Mới")//chức năng thêm mới { string hinhanh = "no_picture.gif"; if (flimg.HasFile == true) { hinhanh = flimg.FileName; } if (TinTuc_Info.Add(hinhanh, txtTieuDe.Text, txtTomTat.Text, txtNoiDung.Text, DateTime.Now, ckbTinhTrang.Checked)) { upload(); ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('Tạo thành công');location.href='admin.aspx?page=tintuc';", true); } else { ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('không thành công,vui lòng kiểm tra lại');location.href='admin.aspx?page=tintuc';", true); } } else//chức năng cập nhật { string image; int id = Convert.ToInt32(HiddenField_Id.Value.Trim()); if (flimg.HasFile)//nếu cập nhật lại ảnh thì upload ảnh { image = flimg.FileName; upload(); } else//không thì lấy ảnh củ { image = HiddenField_HinhAnh.Value; } if (TinTuc_Info.Update(id, image, txtTieuDe.Text, txtTomTat.Text, txtNoiDung.Text, ckbTinhTrang.Checked)) { ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('Tin tức đả được Cập nhật thành công');location.href='admin.aspx?page=tintuc';", true); } else { ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('Lổi cập nhật');location.href='admin.aspx?page=tintuc';", true); } } }
protected void Page_Load(object sender, EventArgs e) { GridView1.DataSource = TinTuc_Info.getall(); GridView1.DataBind(); MultiView1.ActiveViewIndex = 0; }