Parameter 클래스

정의

데이터 소스 제어에서 애플리케이션 변수, 사용자 ID/선택 항목 및 기타 데이터에 바인딩하는 데 사용할 메커니즘을 제공합니다. 모든 ASP.NET 매개 변수 형식에 대한 기본 클래스로 사용됩니다.

public ref class Parameter : ICloneable, System::Web::UI::IStateManager
public class Parameter : ICloneable, System.Web.UI.IStateManager
type Parameter = class
    interface ICloneable
    interface IStateManager
Public Class Parameter
Implements ICloneable, IStateManager
상속
Parameter
파생
구현

예제

다음 예제에서는 선택한 값을 사용 하는 방법을 보여 줍니다는 DropDownList w에서 컨트롤here SQL 쿼리의 절. 이 예제에서는 사용 합니다 ControlParameter 클래스에서 파생 되는 ControlParameter 클래스입니다.

요소는 SelectCommandDropDownList1 이 이동해야 하는 "@Title" 매개 변수를 사용하여 쿼리를 정의합니다. ControlParameter 요소는 "@Title" 자리 표시자가 컨트롤의 SelectedValue 속성 DropDownList1 값으로 대체되도록 지정합니다. ControlParameter 요소에 추가 됩니다는 SelectParameters 의 컬렉션을 SqlDataSource 컨트롤입니다.

<!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" runat="server">

      <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          autopostback="True">
          <asp:listitem selected="True">Sales Representative</asp:listitem>
          <asp:listitem>Sales Manager</asp:listitem>
          <asp:listitem>Vice President, Sales</asp:listitem>
      </asp:dropdownlist></p>

      <asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT LastName FROM Employees WHERE Title = @Title">
          <selectparameters>
              <asp:controlparameter name="Title" controlid="DropDownList1" propertyname="SelectedValue"/>
          </selectparameters>
      </asp:sqldatasource>

      <p><asp:listbox
          id="ListBox1"
          runat="server"
          datasourceid="SqlDataSource1"
          datatextfield="LastName">
      </asp:listbox></p>

    </form>
  </body>
</html>
<!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" runat="server">

      <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          autopostback="True">
          <asp:listitem selected="True">Sales Representative</asp:listitem>
          <asp:listitem>Sales Manager</asp:listitem>
          <asp:listitem>Vice President, Sales</asp:listitem>
      </asp:dropdownlist></p>

      <asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT LastName FROM Employees WHERE Title = @Title">
          <selectparameters>
              <asp:controlparameter name="Title" controlid="DropDownList1" propertyname="SelectedValue"/>
          </selectparameters>
      </asp:sqldatasource>

      <p><asp:listbox
          id="ListBox1"
          runat="server"
          datasourceid="SqlDataSource1"
          datatextfield="LastName">
      </asp:listbox></p>

    </form>
  </body>
</html>

다음 예제에서는 이전 쿼리와 비슷합니다 하지만 태그 대신 코드를 사용 합니다. 페이지가 처음으로 로드 하는 경우는 DropDownList 컨트롤에 선택한 값 없음-및 DefaultValue 속성을는 Parameter 개체를 사용 합니다.

<%@ Page Language="C#" CodeFile="param1acs.aspx.cs" Inherits="param1acs_aspx" %>
<!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" runat="server">
    <div>
        <asp:DropDownList
          runat="server"
          AutoPostBack="True"
          id="DropDownList1">
            <asp:ListItem Value="USA">USA</asp:ListItem>
            <asp:ListItem Value="UK">UK</asp:ListItem>
         </asp:DropDownList>

        <asp:DataGrid
          runat="server"
          id="DataGrid1" />    
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="param1avb.aspx.vb" Inherits="param1avb_aspx" %>
<!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" runat="server">
    <div>
        <asp:DropDownList
          runat="server"
          AutoPostBack="True"
          id="DropDownList1">
            <asp:ListItem Value="USA">USA</asp:ListItem>
            <asp:ListItem Value="UK">UK</asp:ListItem>
         </asp:DropDownList>

        <asp:DataGrid
          runat="server"
          id="DataGrid1" />    
    </div>
    </form>
</body>
</html>

다음 코드는 이전 예제의 페이지에 대 한 코드 숨김 클래스를 보여줍니다.

public partial class param1acs_aspx : System.Web.UI.Page 
{
    private void Page_Load(object sender, System.EventArgs e)
    {
        SqlDataSource sqlSource = new SqlDataSource(
          ConfigurationManager.ConnectionStrings["MyNorthwind"].ConnectionString,
          "SELECT FirstName, LastName FROM Employees WHERE Country = @country;");

        ControlParameter country = new ControlParameter();
        country.Name = "country";
        country.Type = TypeCode.String;
        country.ControlID = "DropDownList1";
        country.PropertyName = "SelectedValue";

        // If the DefaultValue is not set, the DataGrid does not
        // display anything on the first page load. This is because
        // on the first page load, the DropDownList has no
        // selected item, and the ControlParameter evaluates to
        // String.Empty.
        country.DefaultValue = "USA";

        sqlSource.SelectParameters.Add(country);

        // Add the SqlDataSource to the page controls collection.
        Page.Controls.Add(sqlSource);

        DataGrid1.DataSource = sqlSource;
        DataGrid1.DataBind();
    }
}
Partial Class param1avb_aspx
   Inherits System.Web.UI.Page
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim sqlSource As SqlDataSource

        sqlSource = New SqlDataSource(ConfigurationManager.ConnectionStrings("MyNorthwind").ConnectionString, "SELECT FirstName, LastName FROM Employees WHERE Country = @country;")
        Dim country As New ControlParameter()
        country.Name = "country"
        country.Type = TypeCode.String
        country.ControlID = "DropDownList1"
        country.PropertyName = "SelectedValue"
        ' If the DefaultValue is not set, the DataGrid does not
        ' display anything on the first page load. This is because
        ' on the first page load, the DropDownList has no
        ' selected item, and the ControlParameter evaluates to
        ' String.Empty.
        country.DefaultValue = "USA"
        sqlSource.SelectParameters.Add(country)

        ' Add the SqlDataSource to the page controls collection.
        Page.Controls.Add(sqlSource)


        DataGrid1.DataSource = sqlSource
        DataGrid1.DataBind()

    End Sub
End Class

다음 코드 예제를 확장 하는 방법에 설명 합니다 Parameter 데이터 소스 컨트롤 및 기타 컨트롤 데이터 바인딩 시나리오에서 사용할 수 있는 새 매개 변수 형식을 만드는 클래스입니다. 데이터 소스 컨트롤에서 사용할 수는 StaticParameter Web Forms 페이지에 선언 된 모든 개체, 일반적으로 문자열의 값에 바인딩할 매개 변수입니다.

namespace Samples.AspNet {

  using System;
  using System.ComponentModel;
  using System.Security.Permissions;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;

  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public class StaticParameter : Parameter {

    public StaticParameter() {
    }
    // The StaticParameter(string, object) constructor
    // initializes the DataValue property and calls the
    // Parameter(string) constructor to initialize the Name property.
    public StaticParameter(string name, object value) : base(name) {
      DataValue = value;
    }
    // The StaticParameter(string, TypeCode, object) constructor
    // initializes the DataValue property and calls the
    // Parameter(string, TypeCode) constructor to initialize the Name and
    // Type properties.
    public StaticParameter(string name, TypeCode type, object value) : base(name, type) {
      DataValue = value;
    }
    // The StaticParameter copy constructor is provided to ensure that
    // the state contained in the DataValue property is copied to new
    // instances of the class.
    protected StaticParameter(StaticParameter original) : base(original) {
      DataValue = original.DataValue;
    }

    // The Clone method is overridden to call the
    // StaticParameter copy constructor, so that the data in
    // the DataValue property is correctly transferred to the
    // new instance of the StaticParameter.
    protected override Parameter Clone() {
      return new StaticParameter(this);
    }
    // The DataValue can be any arbitrary object and is stored in ViewState.
    public object DataValue {
      get {
        return ViewState["Value"];
      }
      set {
        ViewState["Value"] = value;
      }
    }
    // The Value property is a type safe convenience property
    // used when the StaticParameter represents string data.
    // It gets the string value of the DataValue property, and
    // sets the DataValue property directly.
    public string Value {
      get {
        object o = DataValue;
        if (o == null || !(o is string))
          return String.Empty;
        return (string)o;
      }
      set {
        DataValue = value;
        OnParameterChanged();
      }
    }

    // The Evaluate method is overridden to return the
    // DataValue property instead of the DefaultValue.
    protected override object Evaluate(HttpContext context, Control control) {

      if (context.Request == null)
          return null;

      return DataValue;
    }
  }
}
Imports System.ComponentModel
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet

<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class StaticParameter
   Inherits Parameter


   Public Sub New()
   End Sub

  ' The StaticParameter(string, object) constructor
  ' initializes the DataValue property and calls the
  ' Parameter(string) constructor to initialize the Name property.
   Public Sub New(name As String, value As Object)
      MyBase.New(name)
      DataValue = value
   End Sub

   ' The StaticParameter(string, TypeCode, object) constructor
   ' initializes the DataValue property and calls the
   ' Parameter(string, TypeCode) constructor to initialize the Name and
   ' Type properties.
   Public Sub New(name As String, type As TypeCode, value As Object)
      MyBase.New(name, type)
      DataValue = value
   End Sub
   ' The StaticParameter copy constructor is provided to ensure that
   ' the state contained in the DataValue property is copied to new
   ' instances of the class.
   Protected Sub New(original As StaticParameter)
      MyBase.New(original)
      DataValue = original.DataValue
   End Sub

   ' The Clone method is overridden to call the
   ' StaticParameter copy constructor, so that the data in
   ' the DataValue property is correctly transferred to the
   ' new instance of the StaticParameter.
   Protected Overrides Function Clone() As Parameter
      Return New StaticParameter(Me)
   End Function

   ' The DataValue can be any arbitrary object and is stored in ViewState.
   Public Property DataValue() As Object
      Get
         Return ViewState("Value")
      End Get
      Set
         ViewState("Value") = value
      End Set
   End Property
   ' The Value property is a type safe convenience property
   ' used when the StaticParameter represents string data.
   ' It gets the string value of the DataValue property, and
   ' sets the DataValue property directly.
   Public Property Value() As String
      Get
         Dim o As Object = DataValue
         If o Is Nothing OrElse Not TypeOf o Is String Then
            Return String.Empty
         End If
         Return CStr(o)
      End Get
      Set
         DataValue = value
         OnParameterChanged()
      End Set
   End Property
   ' The Evaluate method is overridden to return the
   ' DataValue property instead of the DefaultValue.
   Protected Overrides Function Evaluate(context As HttpContext, control As Control) As Object
      If context Is Nothing Then
          Return Nothing
      Else
          Return DataValue
      End If
   End Function
End Class

End Namespace ' Samples.AspNet

설명

Parameter 클래스는 매개 변수가 있는 SQL 쿼리를 필터링 식, 매개 변수를 나타내는 또는 선택, 필터링 또는 데이터를 수정 하려면 ASP.NET 데이터 소스 제어는 비즈니스 개체 메서드 호출을 사용 합니다. Parameter 개체는 ParameterCollection 개체에 포함되어 있습니다. Parameter 개체는 어떤 방법을 사용 되는 데이터 소스 컨트롤에서 데이터와 상호 작용을 나타내는 변수 값을 바인딩할 런타임에 평가 됩니다.

파생 된 클래스를 사용 하 여 Parameter 데이터 원본 및 데이터 웹 기반 애플리케이션을 빌드할 데이터 바인딩된 컨트롤을 사용 하 여 합니다. 이러한 매개 변수 클래스는 특정 유형의 SQL 쿼리 문자열, 비즈니스 개체 메서드 매개 변수 등의 자리 표시자에 웹 애플리케이션에서 찾은 값을 바인딩할 데이터 소스 컨트롤에서 사용 됩니다. 다음 표에서 ASP.NET에 포함 된 매개 변수 형식을 나열 합니다.

ControlParameter 웹 서버 컨트롤의 모든 공용 속성에 바인딩합니다.
FormParameter 양식 필드에 바인딩합니다.
SessionParameter 세션 상태 필드를 바인딩합니다.
RouteParameter 경로 URL 매개 변수를 바인딩합니다.
CookieParameter 쿠키 필드를 바인딩합니다.
QueryStringParameter 쿼리 문자열 매개 변수를 바인딩합니다.
ProfileParameter 프로필 필드에 바인딩합니다.

기본 확장 Parameter 사용자 고유의 사용자 지정 매개 변수 형식을 구현 하려는 경우 클래스입니다.

Parameter 개체는 매우 간단한:가지고 NameType 속성에 선언적으로 나타낼 수 있습니다 및 여러 HTTP 요청에서 상태를 추적할 수 있습니다. 모든 매개 변수는 지원를 DefaultValue 매개 변수 값에 바인딩된 이지만 값으로 계산 되는 사례에 대 한 속성인 null 런타임 시.

컬렉션을 사용 하는 경우 Parameter 개체 데이터 소스 컨트롤을 사용 하 여 컬렉션에서 해당 순서 중요할 수 있습니다. 매개 변수를 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. SqlDataSource 컨트롤을 사용 하 여 매개 변수를 사용 하 여 하 고 ObjectDataSource 컨트롤을 사용 하 여 매개 변수를 사용 하 여입니다.

생성자

Parameter()

Parameter 클래스의 새로운 기본 인스턴스를 초기화합니다.

Parameter(Parameter)

지정된 원본 인스턴스의 값을 사용하여 Parameter 클래스의 새 인스턴스를 초기화합니다.

Parameter(String)

지정된 이름을 사용하여 Parameter 클래스의 새 인스턴스를 초기화합니다.

Parameter(String, DbType)

지정된 이름 및 데이터베이스 형식을 사용하여 Parameter 클래스의 새 인스턴스를 초기화합니다.

Parameter(String, DbType, String)

지정된 이름, 지정된 데이터베이스 형식 및 Parameter 속성에 대한 지정된 값을 사용하여 DefaultValue 클래스의 새 인스턴스를 초기화합니다.

Parameter(String, TypeCode)

지정된 이름 및 형식을 사용하여 Parameter 클래스의 새 인스턴스를 초기화합니다.

Parameter(String, TypeCode, String)

지정된 이름 및 형식과 Parameter 속성에 대해 지정된 문자열을 사용하여 DefaultValue 클래스의 새 인스턴스를 초기화합니다.

속성

ConvertEmptyStringToNull

Parameter 개체가 바인딩된 값이 Empty일 경우 이 값을 null로 변환할지 여부를 나타내는 값을 가져오거나 설정합니다.

DbType

매개 변수의 데이터베이스 형식을 가져오거나 설정합니다.

DefaultValue

Evaluate(HttpContext, Control) 메서드가 호출될 때 매개 변수가 바인딩된 값이 초기화되지 않은 경우 해당 매개 변수에 사용할 기본값을 지정합니다.

Direction

Parameter 개체가 컨트롤에 값을 바인딩하는 데 사용되는지 아니면 컨트롤이 값을 변경하는 데 사용될 수 있는지를 나타냅니다.

IsTrackingViewState

Parameter 개체가 해당 뷰 상태의 변경 내용을 저장하는지 여부를 나타내는 값을 가져옵니다.

Name

매개 변수의 이름을 가져오거나 설정합니다.

Size

매개 변수의 크기를 가져오거나 설정합니다.

Type

매개 변수의 유형을 가져오거나 설정합니다.

ViewState

같은 페이지에 대한 여러 개의 요청 전반에 Parameter 개체의 뷰 상태를 저장하고 복원하는 데 사용할 수 있는 상태 정보 사전을 가져옵니다.

메서드

Clone()

현재 Parameter 인스턴스의 복제본을 반환합니다.

ConvertDbTypeToTypeCode(DbType)

DbType 값을 해당하는 TypeCode 값으로 변환합니다.

ConvertTypeCodeToDbType(TypeCode)

TypeCode 값을 해당하는 DbType 값으로 변환합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
Evaluate(HttpContext, Control)

Parameter 개체의 값을 업데이트하고 반환합니다.

GetDatabaseType()

CLR 형식의 현재 DbType 인스턴스에 해당하는 Parameter 값을 가져옵니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
LoadViewState(Object)

데이터 소스 뷰를 이전에 저장된 뷰 상태로 복원합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnParameterChanged()

OnParametersChanged(EventArgs) 개체가 들어 있는 ParameterCollection 컬렉션의 Parameter 메서드를 호출합니다.

SaveViewState()

페이지가 서버에 포스트백된 이후에 발생한 Parameter 개체의 뷰 상태 변경 사항을 저장합니다.

SetDirty()

Parameter 개체를 해당 상태가 뷰 상태에 기록되는 개체로 표시합니다.

ToString()

이 인스턴스의 값을 해당하는 문자열 표현으로 변환합니다.

TrackViewState()

Parameter 개체가 뷰 상태의 변경 내용을 추적하도록 합니다. 이렇게 하면 해당 뷰 상태의 변경 내용을 컨트롤의 ViewState 개체에 저장하여 같은 페이지에 대한 여러 요청에서 일관되게 유지할 수 있습니다.

명시적 인터페이스 구현

ICloneable.Clone()

현재 Parameter 인스턴스의 복제본을 반환합니다.

IStateManager.IsTrackingViewState

Parameter 개체가 해당 뷰 상태의 변경 내용을 저장하는지 여부를 나타내는 값을 가져옵니다.

IStateManager.LoadViewState(Object)

데이터 소스 뷰를 이전에 저장된 뷰 상태로 복원합니다.

IStateManager.SaveViewState()

페이지가 서버에 포스트백된 이후에 발생한 Parameter 개체의 뷰 상태 변경 사항을 저장합니다.

IStateManager.TrackViewState()

Parameter 개체가 뷰 상태의 변경 내용을 추적하도록 합니다. 이렇게 하면 해당 뷰 상태의 변경 내용을 컨트롤의 ViewState 개체에 저장하여 같은 페이지에 대한 여러 요청에서 일관되게 유지할 수 있습니다.

적용 대상

추가 정보