Бөлісу құралы:


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

Значение свойства

Строка, которая служит значением по умолчанию, Parameter когда значение, к которому она привязана, не может быть разрешена или неинициализирована.

Примеры

В следующем примере кода показано, как получить одну запись данных с помощью ObjectDataSource элемента управления и отобразить ее в элементе DetailsView управления. Элемент ObjectDataSource управления получает определенную запись сотрудника, вызывая GetEmployee метод EmployeeLogic класса. Для GetEmployee метода требуется параметр идентификатора сотрудника. Элемент ObjectDataSource управления использует QueryStringParameter объект в своей SelectParameters коллекции для передачи идентификатора методу GetEmployee в этом примере.

Чтобы просмотреть пример реализации EmployeeLogic класса и GetEmployee метода, ознакомьтесь с обзором 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 используется в сценариях, когда параметр привязан к значению, но значение или null не может быть разрешено при Parameter оценке объекта.

DefaultValue Если свойство параметра изменено, OnParameterChanged вызывается метод.

Применяется к