SessionParameter Constructor (String, TypeCode, String)


Initializes a new named and strongly typed instance of the SessionParameter class, using the specified string to identify which session state name/value pair to bind to.

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

public SessionParameter(
	string name,
	TypeCode type,
	string sessionField


Type: System.String

The name of the parameter.

Type: System.TypeCode

The type that the parameter represents. The default is TypeCode.Object.

Type: System.String

The name of the HttpSessionState name/value pair that the parameter object is bound to. The default is Empty.

The Direction and ConvertEmptyStringToNull properties are initialized with default values.

The following code example demonstrates how to use the SessionParameter constructor to create a SessionParameter object and use it with a SqlDataSource control to display data in a DataGrid control.

<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
    SqlDataSource OdbcToSql = new SqlDataSource();

    // Connect to SQL Server using an ODBC DSN.
    OdbcToSql.ProviderName= "System.Data.Odbc";
    OdbcToSql.ConnectionString = "dsn=MyOdbcDsn;";

    // Use an ODBC parameterized query syntax.
    OdbcToSql.SelectCommand = "SELECT EmployeeID FROM Employees " +
                              " WHERE Country = ? AND ReportsTo = ?";

    // The country parameter has no default value, so be sure to set
    // a Session variable named "country" to "UK" or "USA".
    SessionParameter country =
        new SessionParameter("country",TypeCode.String,"country");

    SessionParameter reportsTo =
        new SessionParameter("report",TypeCode.Int32,"report");
    reportsTo.DefaultValue = "2";


    // Add the DataSourceControl to the page's Controls collection.

    DataGrid1.DataSource = OdbcToSql;

<html xmlns="" >
    <head runat="server">
    <title>ASP.NET Example</title>
        <form id="Form1" method="post" runat="server">
                style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute; TOP: 56px"
                runat="server" />

.NET Framework
Available since 2.0
Return to top