Parameter.DefaultValue Propiedad

Definición

Especifica un valor predeterminado para el parámetro, si el valor al que está enlazado el parámetro no debe estar inicializado cuando se llame al método 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

Valor de propiedad

Una cadena que actúa como valor predeterminado para el objeto Parameter cuando no se puede resolver el valor al que está enlazado o no está inicializado.

Ejemplos

En el ejemplo de código siguiente se muestra cómo recuperar un único registro de datos mediante un ObjectDataSource control y mostrarlo en un DetailsView control . El ObjectDataSource control recupera un registro de empleado específico llamando al GetEmployee método de la EmployeeLogic clase . El GetEmployee método requiere un parámetro de identificador de empleado. El ObjectDataSource control usa un QueryStringParameter objeto de su SelectParameters colección para pasar un identificador al GetEmployee método de este ejemplo.

Para ver la implementación de ejemplo de la EmployeeLogic clase y el GetEmployee método , consulte la información general de la ObjectDataSource clase.

<%@ 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>

Comentarios

La DefaultValue propiedad se usa en escenarios en los que el parámetro está enlazado a un valor, pero el valor es null o no se puede resolver cuando se evalúa el Parameter objeto.

Si se cambia la DefaultValue propiedad del parámetro, se llama al OnParameterChanged método .

Se aplica a