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

属性值

String

一个字符串,当 Parameter 绑定到的值无法解析或者未初始化时,该字符串作为参数对象的默认值。

示例

下面的代码示例演示如何使用 ObjectDataSource 控件检索单个数据记录并将其显示在控件中 DetailsView 。 该 ObjectDataSource 控件通过调用 GetEmployee 类的方法 EmployeeLogic 检索特定的员工记录。 该方法 GetEmployee 需要员工 ID 参数。 该 ObjectDataSource 控件使用 QueryStringParameterSelectParameters 集合中的对象将 ID GetEmployee 传递给本示例中的方法。

若要查看类和GetEmployee方法的示例实现EmployeeLogic,请参阅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属性用于将参数绑定到值的情况,但在计算对象时Parameter,该值是null或无法解析。

DefaultValue如果更改了参数的属性,则会OnParameterChanged调用该方法。

适用于