SessionParameter Constructor (String, TypeCode, String)
Assembly: System.Web (in system.web.dll)
public SessionParameter ( String name, TypeCode type, String sessionField )
public function SessionParameter ( name : String, type : TypeCode, sessionField : String )
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.
<%@ 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>
<body MS_POSITIONING="GridLayout">
<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 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.