public void DoADOStuff() { string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; string sql = "Select * from Students"; SqlConnection conn = new SqlConnection(cs); SqlCommand cmd = new SqlCommand(sql, conn); List <StudentClass> liststudents = new List <StudentClass>(); conn.Open(); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { StudentClass student = new StudentClass(); student.id = Convert.ToInt32(rd["Id"]); student.FName = rd["fName"].ToString(); student.LName = rd["lName"].ToString(); student.Gender = rd["gender"].ToString(); liststudents.Add(student); } conn.Close(); GridView1.DataSource = liststudents; GridView1.DataBind(); }
protected void btnLambdaGetStudents_Click(object sender, EventArgs e) { StudentClass studentclass = new StudentClass(); //GridView3.DataSource = studentclass.GetAllStudents(); //GridView3.DataBind(); //IEnumarable<StudentClass> StudentClass. IEnumerable <StudentClass> qryResult = studentclass.GetAllStudents().Where(student => student.Gender == "Male"); GridView3.DataSource = qryResult; GridView3.DataBind(); }
public List <StudentClass> GetAllStudents() { List <StudentClass> listStudentClass = new List <StudentClass>(); StudentClass student1 = new StudentClass(); student1.id = 101; student1.FName = "Minnie"; student1.LName = "Mouse"; student1.Gender = "Female"; listStudentClass.Add(student1); StudentClass student2 = new StudentClass(); student2.id = 102; student2.FName = "Steve"; student2.LName = "Martin"; student2.Gender = "Male"; listStudentClass.Add(student2); StudentClass student3 = new StudentClass(); student3.id = 103; student3.FName = "Jane"; student3.LName = "Doe"; student3.Gender = "Female"; listStudentClass.Add(student3); StudentClass student4 = new StudentClass(); student4.id = 104; student4.FName = "Joe"; student4.LName = "Dirt"; student4.Gender = "Male"; listStudentClass.Add(student4); //IEnumerable<StudentClass> students = GetAllStudents().Where(student => student.Gender == "Male"); //return students; //return student1.ToList(); return(listStudentClass.ToList()); }