Code
Step 1:
First we will create new Web Application in VS 2011.
Step 2:
Now we'll create public method which will return list of objects.
public
IQueryable<Employee>
GetEmployees([QueryString("id")]int
id = 0)
{
IList<Employee> custlist = new
List<Employee>();
custlist.Add(new
Employee { ID = 1, Name =
"Employee 1", Salary = 1000 });
custlist.Add(new
Employee { ID = 2, Name =
"Employee 2", Salary = 2000 });
custlist.Add(new
Employee { ID = 3, Name =
"Employee 3", Salary = 3000 });
custlist.Add(new
Employee { ID = 4, Name =
"Employee 4", Salary = 4000 });
custlist.Add(new
Employee { ID = 5, Name =
"Employee 5", Salary = 5000 });
custlist.Add(new
Employee { ID = 6, Name =
"Employee 6", Salary = 6000 });
custlist.Add(new
Employee { ID = 7, Name =
"Employee 7", Salary = 7000 });
return custlist.AsQueryable<Employee>().Where(c => c.ID == id);
}
public class
Employee
{
public
int ID { get;
set; }
public
string Name { get;
set; }
public
int Salary { get;
set; }
}
Step 3:
Now we'll add Data control in aspx page. I have added GridView Control.
<asp:GridView
ID="GridView1"
SelectMethod="GetEmployees"
AutoGenerateColumns="true"
PageSize="3"
AllowPaging="true"
AllowSorting="true"
runat="server">
</asp:GridView>
Step 4:
Now we'll run our application and see the output.
![asp.net.jpg]()