Parameter.DefaultValue 屬性

定義

指定參數的預設值,當呼叫 Evaluate(HttpContext, Control) 方法時,要繫結的值應是此參數未初始化的值。Specifies a default value for the parameter, should the value that the parameter is bound to be uninitialized when the Evaluate(HttpContext, Control) method is called.

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

屬性值

String

當無法解析或未初始化其繫結至的值時,這個字串會做為 Parameter 的預設值。A string that serves as a default value for the Parameter when the value it is bound to cannot be resolved or is uninitialized.

範例

下列程式碼範例示範如何使用控制項取出單一資料記錄 ObjectDataSource ,並將其顯示在控制項中 DetailsViewThe following code example demonstrates how to retrieve a single data record using an ObjectDataSource control and display it in a DetailsView control. ObjectDataSource控制項藉由呼叫類別的方法,來抓取特定員工記錄 GetEmployee EmployeeLogicThe ObjectDataSource control retrieves a specific employee record by calling the GetEmployee method of the EmployeeLogic class. GetEmployee方法需要員工識別碼參數。The GetEmployee method requires an employee ID parameter. ObjectDataSource控制項使用 QueryStringParameter 其集合中的物件 SelectParameters ,將識別碼傳遞給 GetEmployee 此範例中的方法。The ObjectDataSource control uses a QueryStringParameter object in its SelectParameters collection to pass an ID to the GetEmployee method in this example.

若要查看 EmployeeLogic 類別和方法的範例執行 GetEmployee ,請參閱 ObjectDataSource 類別總覽。To view the example implementation of the EmployeeLogic class and the GetEmployee method, see the ObjectDataSource class overview.

<%@ 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 評估物件時,值是或無法解析 ParameterThe DefaultValue property is used in scenarios where the parameter is bound to a value, but the value is null or cannot be resolved when the Parameter object is evaluated.

如果 DefaultValue 參數的屬性變更,則 OnParameterChanged 會呼叫方法。If the DefaultValue property of the parameter is changed, the OnParameterChanged method is called.

適用於