protected void Monster_Insert_ItemCreated(object sender, EventArgs e) { if (Monster_Insert.CurrentMode == FormViewMode.Insert) { TextBox UserID = Monster_Insert.FindControl("user_idTextBox") as TextBox; UserID.Text = Session["User_id"].ToString(); Creature_GridView.DataBind(); Attack_GridView.DataBind(); Monster_Name_Source.DataBind(); var dropDownList = Attack_Insert.FindControl("creature_DropDownList") as DropDownList; dropDownList.DataBind(); dropDownList.Items.Insert(0, new ListItem("Select Creature")); } }
protected void Monster_Insert_ItemInserting(object sender, FormViewInsertEventArgs e) { //prevent user from adding monsters with same name var dropDownList = Attack_Insert.FindControl("creature_DropDownList") as DropDownList; TextBox monsterName = Monster_Insert.FindControl("creature_nameTextBox") as TextBox; if (dropDownList.Items.FindByText(monsterName.Text) != null) { e.Cancel = true; MonsterErrorLabel.Visible = true; MonsterErrorLabel.Text = "Cannot have two monsters with the same name"; } else { MonsterErrorLabel.Visible = false; } }