Wednesday, August 29, 2012

ASP.NET test new SelectMethod GridView features of Framework 4.5 VS2012.

Introduction

This project i test on a latest release of VS2012 RC. With this version you can binding model with SelectMethod GridView.
We can download Visual studio 2012 Ultimate RC here .

Step 1: AddAdd Gridview set AutoGenerateColumns="true" and pick your SelectMethod.

Step 2: Create CustomerData Class and create ID and name property.

    public class CustomerData
    {
        private string _CustomerID;
        private string _CustomerName;

        public string CustomerID
        {
            get { return _CustomerID; }
            set { _CustomerID = value; }
        }

        public string CustomerName
        {
            get { return _CustomerName; }
            set { _CustomerName = value; }
        }
    }
    

Step 3: Create mehod set to the same name as SelectMethod in Gridview.
We could define method as IQueryable for returned CustomerData.

    public IQueryable<CustomerData> GridView1_GetData()
    {
        List<CustomerData> cl = new List<CustomerData>();
        CustomerData c = new CustomerData();
        c.CustomerID = "1";
        c.CustomerName = "Bank of America";
        cl.Add(c);

        c = new CustomerData();
        c.CustomerID = "2";
        c.CustomerName = "Dow jones";
        cl.Add(c);

        c = new CustomerData();
        c.CustomerID = "3";
        c.CustomerName = "Million Dollar";
        cl.Add(c);

        return cl.AsQueryable();
    }
    

pls enjoy zomdev.

No comments:

Post a Comment