Parameter.DefaultValue Tulajdonság

Definíció

A paraméter alapértelmezett értékét adja meg, ha a metódus meghívásakor Evaluate(HttpContext, Control) a paraméter nem inicializálódik.

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

Tulajdonság értéke

Az a sztring, amely alapértelmezett értékként szolgál arra az Parameter értékre vonatkozóan, amelyhez kötött, nem oldható fel vagy nem inicializálható.

Példák

Az alábbi példakód bemutatja, hogyan kér le egyetlen adatrekordot egy ObjectDataSource vezérlőelem használatával, és hogyan jelenítheti meg azt egy DetailsView vezérlőben. A ObjectDataSource vezérlő egy adott alkalmazotti rekordot kér le az GetEmployeeEmployeeLogic osztály metódusának meghívásával. A GetEmployee metódushoz egy alkalmazotti azonosító paraméter szükséges. A ObjectDataSource vezérlő egy QueryStringParameter objektumot használ a gyűjteményében SelectParameters , hogy egy azonosítót adjon át a GetEmployee példában szereplő metódusnak.

Az osztály és a EmployeeLogic metódus példa implementációjának GetEmployee megtekintéséhez tekintse meg az ObjectDataSource osztály áttekintését.

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

Megjegyzések

A DefaultValue tulajdonság olyan helyzetekben használatos, ahol a paraméter egy értékhez van kötve, de az érték null nem oldható fel az Parameter objektum kiértékelésekor.

Ha a DefaultValue paraméter tulajdonsága módosul, a OnParameterChanged metódus meghívása történik.

A következőre érvényes: