SessionParameter Constructor (String, TypeCode, String)
.NET Framework (current version)
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.
Assembly: System.Web (in System.Web.dll)
Parameters
- name
-
Type:
System.String
The name of the parameter.
- type
-
Type:
System.TypeCode
The type that the parameter represents. The default is TypeCode.Object.
- sessionField
-
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" "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.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"; OdbcToSql.SelectParameters.Add(country); OdbcToSql.SelectParameters.Add(reportsTo); // Add the DataSourceControl to the page's Controls collection. Page.Controls.Add(OdbcToSql); DataGrid1.DataSource = OdbcToSql; DataGrid1.DataBind(); } </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>
.NET Framework
Available since 2.0
Available since 2.0
Show: