다음을 통해 공유


Parameter.DefaultValue 속성

정의

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

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

속성 값

바인딩된 값을 확인할 수 없거나 초기화되지 않은 경우의 기본값 Parameter 으로 사용되는 문자열입니다.

예제

다음 코드 예제에서는 컨트롤을 사용 하 여 단일 데이터 레코드를 ObjectDataSource 검색 하 고 컨트롤에 DetailsView 표시 하는 방법을 보여 줍니다. 컨트롤은 ObjectDataSource 클래스의 메서드를 호출하여 특정 직원 레코드를 GetEmployee 검색합니다 EmployeeLogic . 이 GetEmployee 메서드에는 직원 ID 매개 변수가 필요합니다. 컨트롤은 ObjectDataSource 컬렉션의 SelectParameters 개체를 QueryStringParameter 사용하여 이 예제의 메서드에 ID를 GetEmployee 전달합니다.

클래스 및 메서드의 예제 구현을 EmployeeLogicGetEmployee 보려면 클래스 개요를 ObjectDataSource 참조하세요.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ 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>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          datasourceid="ObjectDataSource1">
        </asp:detailsview>

<!-- Security Note: The ObjectDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of input from the client.
     Security Note: To validate the value of the QueryStringParameter, handle the Selecting event. -->

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          typename="Samples.AspNet.CS.EmployeeLogic" >
          <selectparameters>
            <asp:querystringparameter name="EmployeeID" querystringfield="empid" defaultvalue="-1" />
          </selectparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ 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>
    <title>ObjectDataSource - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          datasourceid="ObjectDataSource1">
        </asp:detailsview>

<!-- Security Note: The ObjectDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of input from the client.
     Security Note: To validate the value of the QueryStringParameter, handle the Selecting event. -->

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          typename="Samples.AspNet.VB.EmployeeLogic" >
          <selectparameters>
            <asp:querystringparameter name="EmployeeID" querystringfield="empid" defaultvalue="-1" />
          </selectparameters>
        </asp:objectdatasource>

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

설명

DefaultValue 속성은 매개 변수가 값에 바인딩되어 있지만 개체를 평가할 때 값을 null 확인할 수 없거나 확인할 수 없는 시나리오에서 Parameter 사용됩니다.

매개 변수의 DefaultValue 속성이 변경되면 메서드가 OnParameterChanged 호출됩니다.

적용 대상