SessionParameter.SessionField 属性

定义

获取或设置此参数绑定到的会话变量的名称。

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

属性值

String

一个字符串,用于标识此参数绑定到的 HttpSessionState

示例

下面的代码示例演示如何以声明方式创建对象SessionParameter、设置对象 SessionField NameDefaultValue属性,并将其添加到SelectParameters控件的SqlDataSource集合中。 控件GridView显示控件提交的SqlDataSourceSQL查询的结果。

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

下面的代码示例演示如何以编程方式设置 SessionField 对象的属性 SessionParameter

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

注解

SessionField 属性标识与 Web 浏览器关联的当前会话对象中存储的名称/值对。 SessionField当属性标识对的名称时,该SessionParameter属性将在运行时绑定到其相应的值。 如果在会话中找不到预期的会话字符串名称/值对,该方法 Evaluate 会将参数绑定到属性的值 DefaultValue (如果已设置)。 如果未设置该 DefaultValue 属性,该方法 Evaluate 将无法将参数绑定到值。

适用于