Exportar (0) Imprimir
Expandir Tudo
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original

SessionParameter Classe

Vincula o valor de uma variável de sessão para um objeto de parâmetro.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (em System.Web. dll)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class SessionParameter : Parameter

You can use the SessionParameter class to bind the value of an HttpSessionState variable to a parameter used in a parameterized SQL query, business object method, or filtering expression.

The SessionParameter class provides the SessionField property in addition to those inherited from the Parameter class.The SessionField property identifies the session variable from which the SessionParameter retrieves a value.

Observação:

Controls that bind data to the parameter might throw an exception if a SessionParameter object is specified but no corresponding session variable is set.Similarly, they might display no data if the session variable is set with null.Set the DefaultValue property to avoid these situations where appropriate.

The following code example demonstrates how to use a SessionParameter object to bind the value of an employee ID stored in a Web browser session to a parameterized SQL query.The SessionParameter object is added to a SqlDataSource control's SelectParameters collection, and used by the parameterized SQL query set in the SelectCommand property to retrieve data and display it in a GridView control.Because the SessionParameter object has a DefaultValue property set, data will still be displayed even if you do not set a session variable named "empid" before you run this example.

<%@ Page language=%>
<!DOCTYPE html PUBLIC "-

<html xmlns="http:
  <head runat=>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id= method= runat=>
      <p>Show My Orders:</p>

      <asp:SqlDataSource
          id=
          runat=
          ProviderName=
          ConnectionString=
          SelectCommand="SELECT OrderId, CustomerId, OrderDate
                         FROM Orders
                         WHERE EmployeeID = ?
                         ORDER BY CustomerId ASC;">
          <SelectParameters>
              <asp:SessionParameter
                Name=
                SessionField=
                DefaultValue= />
          </SelectParameters>
      </asp:SqlDataSource>

      <p>
      <asp:GridView
          id=
          runat=
          DataSourceID= />
      </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 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>


System.Object
  System.Web.UI.WebControls.Parameter
    System.Web.UI.WebControls.SessionParameter

Quaisquer membros públicos estático (compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.

Contribuições da comunidade

ADICIONAR
Mostrar:
© 2015 Microsoft