SessionParameter.SessionField Proprietà

Definizione

Ottiene o imposta il nome della variabile di sessione a cui si associa il parametro.

public:
 property System::String ^ SessionField { System::String ^ get(); void set(System::String ^ value); };
public string SessionField { get; set; }
member this.SessionField : string with get, set
Public Property SessionField As String

Valore della proprietà

Una stringa che identifica l'oggetto HttpSessionState a cui si associa il parametro.

Esempio

L'esempio SelectParameters di codice seguente illustra come creare in modo dichiarativo un SessionParameter oggetto, impostarne SessionFieldNamele proprietà e DefaultValue e aggiungerlo alla raccolta di un SqlDataSource controllo. Un GridView controllo visualizza i risultati della query SQL inviata dal SqlDataSource controllo .

<%@ 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>

Nell'esempio di codice seguente viene illustrato come impostare a livello di codice la SessionField proprietà di un SessionParameter oggetto.

// 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.
Dim empid As New SessionParameter()
empid.Name = "empid"
empid.Type = TypeCode.Int32
empid.SessionField = "empid"

Commenti

La SessionField proprietà identifica una coppia nome/valore archiviata nell'oggetto sessione corrente associato al Web browser. Mentre la SessionField proprietà identifica il nome della coppia, l'associazione SessionParameter al relativo valore corrispondente in fase di esecuzione. Se la coppia nome/valore della stringa di sessione prevista non viene trovata nella sessione, il Evaluate metodo associa il parametro al valore della DefaultValue proprietà, se impostato. Se la proprietà non è impostata, il DefaultValueEvaluate metodo non riesce a associare il parametro a un valore.

Si applica a