SessionParameter Class

Note: This class is new in the .NET Framework version 2.0.

Binds the value of a session variable to a parameter object.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public ref class SessionParameter : public Parameter
public class SessionParameter extends Parameter
public class SessionParameter extends Parameter

You can use the SessionParameter class to bind the value of an HttpSessionState variable to a parameter used in a parameterized SQL query, business object method, or filtering expression.

The SessionParameter class provides the SessionField property in addition to those inherited from the Parameter class. The SessionField property identifies the session variable from which the SessionParameter retrieves a value.


Controls that bind data to the parameter might throw an exception if a SessionParameter object is specified but no corresponding session variable is set. Similarly, they might display no data if the session variable is set with a null reference (Nothing in Visual Basic). Set the DefaultValue property to avoid these situations where appropriate.

The following code example demonstrates how to use a SessionParameter object to bind the value of an employee ID stored in a Web browser session to a parameterized SQL query. The SessionParameter object is added to a SqlDataSource control's SelectParameters collection, and used by the parameterized SQL query set in the SelectCommand property to retrieve data and display it in a GridView control. Because the SessionParameter object has a DefaultValue property set, data will still be displayed even if you do not set a session variable named "empid" before you run this example.

No code example is currently available or this language may not be supported.
<%@ Page language="VJ#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <form id="Form1" method="post" runat="server">
      <P>Show My Orders:</P>

          SelectCommand = "SELECT OrderId, CustomerId, OrderDate
            FROM Orders
            WHERE EmployeeID = ?
            ORDER BY CustomerId ASC;">
                DefaultValue="5" />

          DataSourceID="OdbcDataSource1" />

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions