/*The front page allows the user to select the team. I wanted to add the statistics and other news article from other website. I will definately be working * on this as my side project. * */ protected void btnSubmit_Click(object sender, EventArgs e) { int a; a = DropDownTeams.SelectedIndex + 1; TeamPlayers Team = new TeamPlayers(); //Calls the teamplayer object which has teamid and teamname as properties Team.TeamID = a; Session["TeamID"] = Team.TeamID; /*While reading through couple of different option to store the ID for the next page * the option to use hidden field was also there. But thought this was easy and both has is similar in security and performance.*/ Response.Redirect("PlayersName.aspx"); //Sends the user to another page. This application does not have the 404 error page. In case of exception to redirect //we can use response.redirect }
public static List <TeamPlayers> GetAllTeams() { List <TeamPlayers> listTeams = new List <TeamPlayers>(); string cs = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;// connection to connectionstring using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("spGetAllTeam", con); //decided to use the stroed procedure as helps to prevent SQL injection, safety. cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { TeamPlayers Team = new TeamPlayers(); Team.TeamID = Convert.ToInt32(rdr["ID"]); Team.TeamName = rdr["TeamName"].ToString(); listTeams.Add(Team); } } return(listTeams); }