ADO Net Database ASP.Net Tutorial

You can use a DataView object to  create a sortable, filterable view of a DataTable.
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    void Page_Load()
    {
        if (Session["ProductsToSort"] == null)
        {
            string connectionString = WebConfigurationManager.ConnectionStrings["Products"].ConnectionString;
            SqlDataAdapter dad = new SqlDataAdapter("SELECT Id,Title,Director FROM Products", connectionString);
            DataTable dtblProducts = new DataTable();
            dad.Fill(dtblProducts);
            Session["ProductsToSort"] = dtblProducts.DefaultView;
        }
        if (!Page.IsPostBack)
            BindProducts();
    }
    void BindProducts()
    {
        grdProducts.DataSource = Session["ProductsToSort"];
        grdProducts.DataBind();
    }
    protected void grdProducts_Sorting(object sender, GridViewSortEventArgs e)
    {
        DataView dvwProducts = (DataView)Session["ProductsToSort"];
        dvwProducts.Sort = e.SortExpression;
        BindProducts();
    }



    Show DataView


    
    

            id="grdProducts"
        AllowSorting="true"
        OnSorting="grdProducts_Sorting"
        Runat="server" />
    

    


File: Web.config

  
             connectionString="Data Source=.\SQLEXPRESS;
         AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" />