Uredi

Deli z drugimi prek


SessionParameter Class

Definition

Binds the value of a session variable to a parameter object.

public ref class SessionParameter : System::Web::UI::WebControls::Parameter
public class SessionParameter : System.Web.UI.WebControls.Parameter
type SessionParameter = class
    inherit Parameter
Public Class SessionParameter
Inherits Parameter
Inheritance
SessionParameter

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="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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">
      <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="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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">
      <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>

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.

Constructors

SessionParameter()

Initializes a new unnamed instance of the SessionParameter class.

SessionParameter(SessionParameter)

Initializes a new instance of the SessionParameter class with the values of the instance specified by the original parameter.

SessionParameter(String, DbType, String)

Initializes a new instance of the SessionParameter class, by using the specified name and type, and binding the parameter to the specified session state name/value pair. This constructor is for database types.

SessionParameter(String, String)

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

SessionParameter(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.

Properties

ConvertEmptyStringToNull

Gets or sets a value indicating whether the value that the Parameter object is bound to should be converted to null if it is Empty.

(Inherited from Parameter)
DbType

Gets or sets the database type of the parameter.

(Inherited from Parameter)
DefaultValue

Specifies a default value for the parameter, should the value that the parameter is bound to be uninitialized when the Evaluate(HttpContext, Control) method is called.

(Inherited from Parameter)
Direction

Indicates whether the Parameter object is used to bind a value to a control, or the control can be used to change the value.

(Inherited from Parameter)
IsTrackingViewState

Gets a value indicating whether the Parameter object is saving changes to its view state.

(Inherited from Parameter)
Name

Gets or sets the name of the parameter.

(Inherited from Parameter)
SessionField

Gets or sets the name of the session variable that the parameter binds to.

Size

Gets or sets the size of the parameter.

(Inherited from Parameter)
Type

Gets or sets the type of the parameter.

(Inherited from Parameter)
ViewState

Gets a dictionary of state information that allows you to save and restore the view state of a Parameter object across multiple requests for the same page.

(Inherited from Parameter)

Methods

Clone()

Returns a duplicate of the current SessionParameter instance.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Evaluate(HttpContext, Control)

Updates and returns the value of the SessionParameter object.

GetDatabaseType()

Gets the DbType value that is equivalent to the CLR type of the current Parameter instance.

(Inherited from Parameter)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
LoadViewState(Object)

Restores the data source view's previously saved view state.

(Inherited from Parameter)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnParameterChanged()

Calls the OnParametersChanged(EventArgs) method of the ParameterCollection collection that contains the Parameter object.

(Inherited from Parameter)
SaveViewState()

Saves the changes to the Parameter object's view state since the time the page was posted back to the server.

(Inherited from Parameter)
SetDirty()

Marks the Parameter object so its state will be recorded in view state.

(Inherited from Parameter)
ToString()

Converts the value of this instance to its equivalent string representation.

(Inherited from Parameter)
TrackViewState()

Causes the Parameter object to track changes to its view state so they can be stored in the control's ViewState object and persisted across requests for the same page.

(Inherited from Parameter)

Explicit Interface Implementations

ICloneable.Clone()

Returns a duplicate of the current Parameter instance.

(Inherited from Parameter)
IStateManager.IsTrackingViewState

Gets a value indicating whether the Parameter object is saving changes to its view state.

(Inherited from Parameter)
IStateManager.LoadViewState(Object)

Restores the data source view's previously saved view state.

(Inherited from Parameter)
IStateManager.SaveViewState()

Saves the changes to the Parameter object's view state since the time the page was posted back to the server.

(Inherited from Parameter)
IStateManager.TrackViewState()

Causes the Parameter object to track changes to its view state so they can be stored in the control's ViewState object and persisted across requests for the same page.

(Inherited from Parameter)

Applies to

See also