Sorting a DataView stored in Session state. : Session Variables « Sessions « ASP.NET Tutorial

Home
ASP.NET Tutorial
1.ASP.Net Instroduction
2.Language Basics
3.ASP.net Controls
4.HTML Controls
5.Page Lifecycle
6.Response
7.Collections
8.Validation
9.Development
10.File Directory
11.Sessions
12.Cookie
13.Cache
14.Custom Controls
15.Profile
16.Configuration
17.LINQ
18.ADO.net Database
19.Data Binding
20.Ajax
21.Authentication Authorization
22.I18N
23.Mobile
24.WebPart
25.XML
ASP.NET Tutorial » Sessions » Session Variables 
11.3.3.Sorting a DataView stored in Session state.
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    DataView dvProducts;

    void Page_Load()
    {
        dvProducts = (DataView)Session["Products"];
        if (dvProducts == null)
        {
            string conString = WebConfigurationManager.ConnectionStrings["Products"]. ConnectionString;
            SqlDataAdapter dad = new SqlDataAdapter("SELECT Id,Title,Director FROM Products", conString);
            DataTable dtblProducts = new DataTable();
            dad.Fill(dtblProducts);
            dvProducts = new DataView(dtblProducts);
            Session["Products"= dvProducts;
        }
    }

    protected void grdProducts_Sorting(object sender, GridViewSortEventArgs e)
    {
        dvProducts.Sort = e.SortExpression;
    }

    void Page_PreRender()
    {
        grdProducts.DataSource = dvProducts;
        grdProducts.DataBind();
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Session DataView</title>
</head>
<body>
     <form id="form1" runat="server">
     <div>

     <asp:GridView
         id="grdProducts"
         AllowSorting="true"
         EnableViewState="false"
         OnSorting="grdProducts_Sorting"
         Runat="server" />
     <br />
     <asp:LinkButton
         id="lnkReload"
         Text="Reload Page"
         Runat="server" />

     </div>
     </form>
</body>
</html>
11.3.Session Variables
11.3.1.Using Session State
11.3.2.Retrieve the value of an item that you have stored in Session state.
11.3.3.Sorting a DataView stored in Session state.
11.3.4.Save value in text box to session and read it back (VB.net/C#)
11.3.5.Save value to session object and read them back (VB.net)
11.3.6.Store user defined object in Session (C#)
11.3.7.Setting and retrieving objects from the Session using State Service and a base page (C#)
11.3.8.Setting and retrieving objects from the Session using State Service and a base page (VB)
11.3.9.A session-aware base page
11.3.10.Session counter and application counter (C#)
11.3.11.Session counter and application counter (VB)
11.3.12.Look for Variables
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.