Parameter.DefaultValue Parameter.DefaultValue Parameter.DefaultValue Parameter.DefaultValue Property

定義

指定參數的預設值,當呼叫 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

屬性值

當無法解析或未初始化其繫結至的值時,這個字串會做為 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控制項來抓取單一資料記錄,並將它顯示DetailsView在控制項中。The following code example demonstrates how to retrieve a single data record using an ObjectDataSource control and display it in a DetailsView control. 控制項會藉由GetEmployee呼叫EmployeeLogic類別的方法,來抓取特定的員工記錄。 ObjectDataSourceThe ObjectDataSource control retrieves a specific employee record by calling the GetEmployee method of the EmployeeLogic class. GetEmployee方法需要 employee ID 參數。The GetEmployee method requires an employee ID parameter. 控制項會在其QueryStringParameter SelectParameters集合中使用物件,將識別碼傳遞給此GetEmployee範例中的方法。 ObjectDataSourceThe 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>

備註

屬性會在參數系結至值的案例中使用,但值為null或在評估Parameter物件時無法解析。 DefaultValueThe 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.

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

適用於