protected void SearchPlayers_Click(object sender, EventArgs e) { // check age if null/empty if (string.IsNullOrEmpty(Age.Text)) { errormsgs.Add("Age is required."); LoadMessageDisplay(errormsgs, "alert alert-danger"); PlayerGridView.DataSource = null; PlayerGridView.DataBind(); } else { // check age if numeric if (!Regex.IsMatch(Age.Text, @"^\d+$")) { Age.Text = null; errormsgs.Add("Age should be numeric value."); LoadMessageDisplay(errormsgs, "alert alert-danger"); PlayerGridView.DataSource = null; PlayerGridView.DataBind(); } else { // check age if greater than 0 if (int.Parse(Age.Text) <= 0) { errormsgs.Add("Age should be greater than 0."); LoadMessageDisplay(errormsgs, "alert alert-danger"); PlayerGridView.DataSource = null; PlayerGridView.DataBind(); } } } // check if gender is selected if (Gender.SelectedIndex < 0) { errormsgs.Add("Gender is required."); LoadMessageDisplay(errormsgs, "alert alert-danger"); PlayerGridView.DataSource = null; PlayerGridView.DataBind(); } }
protected void PlayerGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { PlayerGridView.PageIndex = e.NewPageIndex; // you must refresh your grid view with a call to the database try { PlayerController sysmgr = new PlayerController(); List <Player> datainfo = sysmgr.Players_GetByTeam(int.Parse(TeamList.SelectedValue)); datainfo.Sort((x, y) => x.FullName.CompareTo(y.FullName)); PlayerGridView.DataSource = datainfo; PlayerGridView.DataBind(); } catch (Exception ex) { errormsgs.Add(GetInnerException(ex).ToString()); LoadMessageDisplay(errormsgs, "alert alert-danger"); } }
protected void SearchButton_Click1(object sender, EventArgs e) { PlayerGridView.DataSource = null; PlayerGridView.DataBind(); //WORKS! if (TeamList.SelectedIndex == 0) { errormsgs.Add("Select a Team to veiw Players."); LoadMessageDisplay(errormsgs, "alert alert-info"); Teaminfo = null; Coach.Text = null; AssistantCoach.Text = null; Wins.Text = "0"; Losses.Text = "0"; PlayerGridView.DataSource = null; PlayerGridView.DataBind(); } else { try { TeamController sysmgr = new TeamController(); Team TeamInfo = sysmgr.Team_Get(int.Parse(TeamList.SelectedValue)); if (TeamInfo == null) { errormsgs.Add("TeamInfo Not Bound"); LoadMessageDisplay(errormsgs, "alert alert-info"); } else { Coach.Text = TeamInfo.Coach; AssistantCoach.Text = TeamInfo.AssistantCoach; if (TeamInfo.Wins == null) { Wins.Text = "0"; } else { Wins.Text = TeamInfo.Wins.ToString(); } if (TeamInfo.Losses == null) { Losses.Text = "0"; } else { Losses.Text = TeamInfo.Losses.ToString(); } } PlayerController plyrmgr = new PlayerController(); List <Player> info = plyrmgr.Players_GetByTeam(int.Parse(TeamList.SelectedValue)); if (info.Count == 0) { errormsgs.Add("No data found for the selected team"); LoadMessageDisplay(errormsgs, "alert alert-info"); } else { info.Sort((x, y) => x.FullName.CompareTo(y.FullName)); PlayerGridView.DataSource = info; PlayerGridView.DataBind(); } } catch (Exception ex) { errormsgs.Add(GetInnerException(ex).ToString()); LoadMessageDisplay(errormsgs, "alert alert-danger"); } } }