protected void Page_Load(object sender, EventArgs e) { //Linq Expression IEnumerable <Student1> students = Student1.GetAllStudents().Where(student => student.Gender == "Male"); //Linq Query Using Sql Like Structure---------------------------------------------------------------------------- //IEnumerable<Student1> students = from student in Student1.GetAllStudents() //where student.Gender == "Male" //select student; GridView1.DataSource = students; GridView1.DataBind(); }
public static List <Student1> GetAllStudents() { List <Student1> students = new List <Student1>(); //---------------------------------------------- Student1 s1 = new Student1 { Id = 101, Name = "Narender Tanwar", Gender = "Male" }; students.Add(s1); Student1 s2 = new Student1 { Id = 102, Name = "Deepak Tanwar", Gender = "Male" }; students.Add(s2); Student1 s3 = new Student1 { Id = 103, Name = "John", Gender = "Male" }; students.Add(s3); Student1 s4 = new Student1 { Id = 104, Name = "Jenny", Gender = "FeMale" }; students.Add(s4); //---------------------------------------------- return(students); }