.NET Framework Class Library SessionParameter Class Binds the value of a session variable to a parameter object.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)

Syntax
Public Class SessionParameter _
Inherits Parameter
public class SessionParameter : Parameter
public ref class SessionParameter : public Parameter
type SessionParameter =
class
inherit Parameter
end
The SessionParameter type exposes the following members.

Methods

Explicit Interface Implementations

Remarks
A SessionParameter object is typically used in order to include the value of an HttpSessionState variable in the Where clause of a database query. The SessionField property identifies the session variable from which the SessionParameter retrieves a value. Note |
|---|
Controls that bind data to a parameter by using a SessionParameter object might throw an exception if the specified session variable is not set. To avoid this error (where appropriate), set the DefaultValue property. |

Examples
The following example shows how to use a SessionParameter object. The example assumes that another page has stored an employee ID value in a session variable named empid. The example page uses the empid session variable in the Where clause of a query and displays the result of the query in a GridView control. Because the DefaultValue property of the SessionParameter object is set to 5, data for the record that has the employeeID value of 5 will still be displayed if no session variable named empid is set before you run the example.
<%@ Page language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<p>Show My Orders:</p>
<asp:SqlDataSource
id="OdbcDataSource1"
runat="server"
ProviderName="System.Data.Odbc"
ConnectionString="dsn=MyOdbcDsn;"
SelectCommand="SELECT OrderId, CustomerId, OrderDate
FROM Orders
WHERE EmployeeID = ?
ORDER BY CustomerId ASC;">
<SelectParameters>
<asp:SessionParameter
Name="empid"
SessionField="empid"
DefaultValue="5" />
</SelectParameters>
</asp:SqlDataSource>
<p>
<asp:GridView
id="GridView1"
runat="server"
DataSourceID="OdbcDataSource1" />
</p>
</form>
</body>
</html>
<%@ Page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<p>Show My Orders:</p>
<asp:SqlDataSource
id="OdbcDataSource1"
runat="server"
ProviderName="System.Data.Odbc"
ConnectionString="dsn=MyOdbcDsn;"
SelectCommand="SELECT OrderId, CustomerId, OrderDate
FROM Orders
WHERE EmployeeID = ?
ORDER BY CustomerId ASC;">
<SelectParameters>
<asp:SessionParameter
Name="empid"
SessionField="empid"
DefaultValue="5" />
</SelectParameters>
</asp:SqlDataSource>
<p>
<asp:GridView
id="GridView1"
runat="server"
DataSourceID="OdbcDataSource1" />
</p>
</form>
</body>
</html>

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

See Also
|
Bibliothèque de classes .NET Framework SessionParameter, classe Lie la valeur d'une variable de session à un objet Parameter.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
Public Class SessionParameter _
Inherits Parameter
public class SessionParameter : Parameter
public ref class SessionParameter : public Parameter
type SessionParameter =
class
inherit Parameter
end
Le type SessionParameter expose les membres suivants.

Méthodes

Implémentations d'interface explicite

Notes
Un objet SessionParameter est généralement utilisé pour inclure la valeur d'une variable HttpSessionState dans la clause Where d'une requête de base de données. La propriété SessionField identifie la variable de session à partir de laquelle le SessionParameter récupère une valeur. Remarque |
|---|
Les contrôles qui lient des données à un paramètre à l'aide d'un objet SessionParameter sont susceptibles de lever une exception si la variable de session spécifiée n'est pas définie. Pour éviter cette erreur (lorsque c'est nécessaire), définissez la propriété DefaultValue. |

Exemples
L'exemple ci-dessous explique comment utiliser un objet SessionParameter. L'exemple suppose qu'une autre page a stocké une valeur Employee ID dans une variable de session nommée empid. La page d'exemple utilise la variable de session empid dans la clause Where d'une requête et affiche le résultat de la requête dans un contrôle GridView. Étant donné que la propriété DefaultValue de l'objet SessionParameter a la valeur 5, les données de l'enregistrement qui ont la valeur employeeID 5 restent affichées si aucune variable de session nommée empid n'est définie avant l'exécution de l'exemple.
<%@ Page language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<p>Show My Orders:</p>
<asp:SqlDataSource
id="OdbcDataSource1"
runat="server"
ProviderName="System.Data.Odbc"
ConnectionString="dsn=MyOdbcDsn;"
SelectCommand="SELECT OrderId, CustomerId, OrderDate
FROM Orders
WHERE EmployeeID = ?
ORDER BY CustomerId ASC;">
<SelectParameters>
<asp:SessionParameter
Name="empid"
SessionField="empid"
DefaultValue="5" />
</SelectParameters>
</asp:SqlDataSource>
<p>
<asp:GridView
id="GridView1"
runat="server"
DataSourceID="OdbcDataSource1" />
</p>
</form>
</body>
</html>
<%@ Page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<p>Show My Orders:</p>
<asp:SqlDataSource
id="OdbcDataSource1"
runat="server"
ProviderName="System.Data.Odbc"
ConnectionString="dsn=MyOdbcDsn;"
SelectCommand="SELECT OrderId, CustomerId, OrderDate
FROM Orders
WHERE EmployeeID = ?
ORDER BY CustomerId ASC;">
<SelectParameters>
<asp:SessionParameter
Name="empid"
SessionField="empid"
DefaultValue="5" />
</SelectParameters>
</asp:SqlDataSource>
<p>
<asp:GridView
id="GridView1"
runat="server"
DataSourceID="OdbcDataSource1" />
</p>
</form>
</body>
</html>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
RéférenceAutres ressources
|