private void cmdThemNguoiPhong_Click(object sender, RoutedEventArgs e) { try { HyperlinkButton cmdThemNguoiPhong = (HyperlinkButton)sender; List<Nguoi_PhongInfo> ListNguoiPhong = new List<Nguoi_PhongInfo>(); ListNguoiPhong = (List<Nguoi_PhongInfo>)grvTheoSoNguoi.ItemsSource; //add new row int Nguoi_PhongID = 0; Nguoi_PhongInfo NguoiPhong = null; if (cmdThemNguoiPhong.Content.Equals("Thêm")) { if (NguoiPhongNextID != -1) { Nguoi_PhongID = NguoiPhongNextID; } NguoiPhong = new Nguoi_PhongInfo(); NguoiPhong.Nguoi_PhongID = Nguoi_PhongID; NguoiPhong.NguoiPhongName = ""; NguoiPhong.CongThem = ""; NguoiPhong.ImageUrl = "Xóa"; ListNguoiPhong.Add(NguoiPhong); } else { Nguoi_PhongID = int.Parse(cmdThemNguoiPhong.CommandParameter.ToString()); for (int i = 0; i < ListNguoiPhong.Count; i++) { if (ListNguoiPhong[i].Nguoi_PhongID == Nguoi_PhongID) { ListNguoiPhong.RemoveAt(i); break; } } } NguoiPhongNextID = Nguoi_PhongID + 1; grvTheoSoNguoi.ItemsSource = null; grvTheoSoNguoi.ItemsSource = ListNguoiPhong; } catch (Exception ex) { throw ex; } }
protected void Nguoi_Phong_Load() { try { //Tao Du Lieu Trong List<Nguoi_PhongInfo> GioPhong = new List<Nguoi_PhongInfo>(); Nguoi_PhongInfo Item = new Nguoi_PhongInfo(); Item.Nguoi_PhongID = 1; Item.NguoiPhongName = "1"; Item.GiaTien = 0; Item.PhanTram = 0; Item.CongThem = ""; Item.ImageUrl = "Thêm"; GioPhong.Add(Item); NguoiPhongNextID = 2; grvTheoSoNguoi.ItemsSource = GioPhong; txtCongThem.Text = ""; } catch (Exception) { throw; } }