Export (0) Print
Expand All
1 out of 5 rated this helpful - Rate this topic

Parameter.DefaultValue Property

Note: This property is new in the .NET Framework version 2.0.

Specifies a default value for the parameter, should the value that the parameter is bound to be uninitialized when the Evaluate method is called.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public string DefaultValue { get; set; }
/** @property */
public String get_DefaultValue ()

/** @property */
public void set_DefaultValue (String value)

public function get DefaultValue () : String

public function set DefaultValue (value : String)

Property Value

A string that serves as a default value for the Parameter when the value it is bound to cannot be resolved or is uninitialized.

The DefaultValue property is used in scenarios where the parameter is bound to a value, but the value is a null reference (Nothing in Visual Basic) or cannot be resolved when the Parameter object is evaluated.

If the DefaultValue property of the parameter is changed, the OnParameterChanged method is called.

The following code example demonstrates how to retrieve a single data record using an ObjectDataSource control and display it in a DetailsView control. The ObjectDataSource control retrieves a specific employee record by calling the GetEmployee method of the EmployeeLogic class. The GetEmployee method requires an employee ID parameter. The ObjectDataSource control uses a QueryStringParameter object in its SelectParameters collection to pass an ID to the GetEmployee method in this example.

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#" %>
<html>
  <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="anID" querystringfield="empid" defaultvalue="-1" />
          </selectparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.jsl" Assembly="Samples.AspNet.jsl" %>
<%@ Page Language="VJ#" %>
<html>
  <head>
    <title>ObjectDataSource - VJ# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          datasourceid="ObjectDataSource1">
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          typename="Samples.AspNet.jsl.EmployeeLogic" >
          <selectparameters>
            <asp:querystringparameter name="anID" querystringfield="empid" defaultvalue="-1" />
          </selectparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.