What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 1771 |  Welcome, Guest!   Register  Login
 Home > Blogs > ASP.NET > Strongly Typed Data Controls Value Provider ASP.NET 4.5 ...
Amitkpatel

Strongly Typed Data Controls Value Provider ASP.NET 4.5

 Blog author: Amitkpatel | Posted on: 6/25/2012 | Category: ASP.NET Blogs | Views: 527 | Status: [Member] | Points: 75 | Alert Moderator   


Introduction: Microsoft introduce new library System.web.Binding. There are lots of new things. One of them is QueryStringAttribute class. With the help of this class we can send directly query string value to method.
Code: Download code ValueProviderSample4.5.zip
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 });
            custlist.Add(new Employee { ID = 8, Name = "Employee 8", Salary = 8000 });
            return custlist.AsQueryable<Employee>().Where(c => c.ID == id);
        }
public class Employee
    {
        public int ID { getset; }
        public string Name { getset; }
        public int Salary { getset; }
    }
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.



Amit Kumar Patel
http://blog.iquestionanswer.co.in
http://www.iquestionanswer.co.in
Found interesting? Add this to:


About Amit Patel

Experience:8 year(s)
Home page:http://www.dotnetchuks.com
Member since:Friday, June 22, 2012
Level:Starter
Status: [Member]
Biography:I am Amit Patel, I have 8yrs of experiences in Microsoft technologies. I am very much passionate about Web technology. My core skill is ASP.NET, WCF, C#, JQuery and CSS
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 7:52:10 PM