using System;
using System.Linq;
using System.Web.UI.WebControls;

public partial class LinqEntitiesOrderBy : System.Web.UI.Page
{

    protected void btnExecutar_Click(object sender, EventArgs e)
    {
        GridDataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridDataBind();
    }

    void GridDataBind()
    {
        using (NorthwindDataContext db = new NorthwindDataContext())
        {
            var query = db.Products
           .OrderBy(c => c.ProductID)
           .Select(produto => new
           {
               IdProduto = produto.ProductID,
               NomeProduto = produto.ProductName
           });

            GridView1.DataSource = query;
            GridView1.DataBind();
        }
    }
}