Blog author:
Amitkpatel | Posted on: 6/25/2012 | Category:
ASP.NET Blogs | Views: 694 | Status:
[Member] |
Points: 75
|
Alert Moderator
Introduction: In the previous version of ASP.NET framework, we have ObjectDataSource control. But now in ASP.NET 4.5 Microsoft integrated ObjectDataSource control with Data Controls. Now Microsoft exposes some property like
Purpose: Now developer can easily bind Data controls with the help of SelectMethod and developer can also do other Data Controls operation with the help if UpdateMethod and DeleteMethod.
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<Customer> GetCustomers()
{
IList<Customer> custlist = new List<Customer>();
custlist.Add(new Customer { ID = 1, Name = "Customer 1", Salary = 1000 });
custlist.Add(new Customer { ID = 2, Name = "Customer 2", Salary = 2000 });
custlist.Add(new Customer { ID = 3, Name = "Customer 3", Salary = 3000 });
custlist.Add(new Customer { ID = 4, Name = "Customer 4", Salary = 4000 });
custlist.Add(new Customer { ID = 5, Name = "Customer 5", Salary = 5000 });
custlist.Add(new Customer { ID = 6, Name = "Customer 6", Salary = 6000 });
custlist.Add(new Customer { ID = 7, Name = "Customer 7", Salary = 7000 });
custlist.Add(new Customer { ID = 8, Name = "Customer 8", Salary = 8000 });
return custlist.AsQueryable<Customer>();
}
public class Customer
{
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="GetCustomers" AutoGenerateColumns="true"
PageSize="3" AllowPaging="true" AllowSorting="true" runat="server">
asp:GridView>
Step 4: Now we'll run our application and see the output.
Amit Kumar Patel
http://blog.iquestionanswer.co.in
http://www.iquestionanswer.co.in
Found interesting? Add this to: