CODE BEHIND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq.SqlClient;
public partial class LinqSelectTop : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (txtContactsSearch.Text.Trim() != string.Empty)
{
var data = (from m in GetStudentList()
select m).Take(Convert.ToInt32(txtContactsSearch.Text.Trim()));
gvLikeOperator.DataSource = data;
gvLikeOperator.DataBind();
}
}
private List<Student> GetStudentList()
{
List<Student> StudentStudents = new List<Student>{
new Student{StudentID=1, StudentName="Amin"},
new Student{StudentID=2, StudentName="Alomgir"},
new Student{StudentID=3, StudentName="Ashikur Rahman"},
new Student{StudentID=4, StudentName="Shamim Ahmed"},
new Student{StudentID=5, StudentName="Amolash"},
new Student{StudentID=6, StudentName="Alum"},
new Student{StudentID=7, StudentName="Abil"},
new Student{StudentID=8, StudentName="Enamul"},
new Student{StudentID=9, StudentName="Nahid"},
new Student{StudentID=10, StudentName="Asraf"},
new Student{StudentID=11, StudentName="Asfaq"},
new Student{StudentID=12, StudentName="kbil"},
new Student{StudentID=13, StudentName="Masum"},
new Student{StudentID=14, StudentName="Nasid"},
new Student{StudentID=15, StudentName="Babu"},
new Student{StudentID=16, StudentName="Titu"}
};
return StudentStudents;
}
public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
}
}