protected void btnCreateHero_Click(object sender, EventArgs e) { var name = TBHeroName.Text; if (name.Length == 0 || name.All(x => x == ' ')) { //msgLabel.Text = "Invalid Hero Name!"; return; } using (var context = new HeroDbConnStr()) { var newHero = new WebFormsWithDbFirst.HeroModelDesigner.Hero() { Name = name }; context.Hero.Add(newHero); context.SaveChanges(); } HeroPage heroPage = (HeroPage)this.Page; heroPage.BindAllHeroNames(); //UpdatePanel heroUpdatePanel = (UpdatePanel)this.Parent.FindControl("HeroUpdatePanel"); //heroUpdatePanel.Update(); }
public void BindAllWeaponNames() { using (var context = new HeroDbConnStr()) { var data = context.Weapon.ToArray(); WeaponNameRepeater.DataSource = data; WeaponNameRepeater.DataBind(); } }
public void BindRepeater() { using (var context = new HeroDbConnStr()) { var data = context.udf_favourite_weapon(); TableRepeater.DataSource = data; TableRepeater.DataBind(); } }
protected void HeroNameRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName != "Delete") { return; } var heroId = int.Parse((string)e.CommandArgument); using (var context = new HeroDbConnStr()) { var hero = context.Hero.SingleOrDefault(x => x.Id == heroId); if (hero != null) { context.Hero.Remove(hero); context.SaveChanges(); BindAllHeroNames(); } } }