SessionParameter.SessionParameter(String, TypeCode, String) Constructor

Initializes a new named and strongly typed instance of the SessionParameter class, using the specified string to identify which HTTP cookie to bind to.

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

public:
SessionParameter (
	String^ name, 
	TypeCode type, 
	String^ sessionField
)
public SessionParameter (
	String name, 
	TypeCode type, 
	String sessionField
)
public function SessionParameter (
	name : String, 
	type : TypeCode, 
	sessionField : String
)
Not applicable.

Parameters

name

The name of the parameter.

type

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

sessionField

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

A SessionParameter object created with the SessionParameter constructor is initialized with the specified parameter name, Type, and string that identifies the HttpSessionState name/value pair that the parameter binds to. Only 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.

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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.set_ProviderName("System.Data.Odbc");
    odbcToSql.set_ConnectionString("dsn=MyOdbcDsn;");

    // Use an ODBC parameterized query syntax.
    odbcToSql.set_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",System.TypeCode.String,"country");

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

    reportsTo.set_DefaultValue("2");
    odbcToSql.get_SelectParameters().Add(country);
    odbcToSql.get_SelectParameters().Add(reportsTo);

    // Add the DataSourceControl to the page's Controls collection.
    get_Page().get_Controls().Add(odbcToSql);
    DataGrid1.set_DataSource(odbcToSql);
    DataGrid1.DataBind();
} //Page_Load

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="Form1" method="post" runat="server">
            <asp:DataGrid
                id="DataGrid1"
                style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute; TOP: 56px"
                runat="server" />
        </form>
    </body>
</html>

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: