Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SessionParameter.SessionField Property

Note: This property is new in the .NET Framework version 2.0.

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

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

public string SessionField { get; set; }
/** @property */
public String get_SessionField ()

/** @property */
public void set_SessionField (String value)

public function get SessionField () : String

public function set SessionField (value : String)

Property Value

A string that identifies the HttpSessionState that the parameter binds to.

The SessionField property identifies a name/value pair that is stored in the current session object associated with the Web browser. While the SessionField property identifies the name of the pair, the SessionParameter binds to its corresponding value at run time. If the expected session string name/value pair is not found in the session, the Evaluate method binds the parameter to the value of the DefaultValue property, if it is set. If the DefaultValue property is not set, the Evaluate method fails to bind the parameter to a value.

The following code example demonstrates how to declaratively create a SessionParameter object, set its Name, SessionField and DefaultValue properties, and add it to the SelectParameters collection of a SqlDataSource control. A GridView control displays the results of the SQL query submitted by the SqlDataSource control.

<%@ Page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

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

The following code example demonstrates how to programmatically set the SessionField property of a SessionParameter object.

// In this example, the session parameter "empid" is set
// after the employee successfully logs in.
SessionParameter empid = new SessionParameter();
empid.Name = "empid";
empid.Type = TypeCode.Int32;
empid.SessionField = "empid";

// In this example, the session parameter "empid" is set
// after the employee successfully logs in.
SessionParameter empid = new SessionParameter();
empid.set_Name("empid");
empid.set_Type(System.TypeCode.Int32);
empid.set_SessionField("empid");

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.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft