ObjectDataSourceView.SelectMethod Propriedade
Definição
Obtém ou define o nome do método ou da função invocada pelo controle ObjectDataSourceView para recuperar dados.Gets or sets the name of the method or function that the ObjectDataSourceView control invokes to retrieve data.
public:
property System::String ^ SelectMethod { System::String ^ get(); void set(System::String ^ value); };
public string SelectMethod { get; set; }
member this.SelectMethod : string with get, set
Public Property SelectMethod As String
Valor da propriedade
Uma cadeia de caracteres que representa o nome do método ou da função usado pelo ObjectDataSourceView para recuperar dados.A string that represents the name of the method or function that the ObjectDataSourceView uses to retrieve data. O padrão é uma cadeia de caracteres vazia ("").The default is an empty string ("").
Exemplos
O exemplo de código a seguir demonstra como um GridView controle pode exibir dados usando um ObjectDataSource controle em uma página Web Forms.The following code example demonstrates how a GridView control can display data using an ObjectDataSource control on a Web Forms page. O ObjectDataSource identifica um nome de classe parcialmente ou totalmente qualificado com sua TypeName propriedade e um método que é chamado para recuperar dados com sua SelectMethod propriedade.The ObjectDataSource identifies a partially or fully qualified class name with its TypeName property and a method that is called to retrieve data with its SelectMethod property. Em tempo de execução, o objeto é criado e o método é chamado usando reflexão.At run time, the object is created and the method is called using reflection. O GridView controle enumera através da IEnumerable coleção retornada pelo SelectMethod e, em seguida, exibe os dados.The GridView control enumerates through the IEnumerable collection that is returned by the SelectMethod, and then displays the data.
<%@ 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:gridview
id="GridView1"
runat="server"
datasourceid="ObjectDataSource1" />
<asp:objectdatasource
id="ObjectDataSource1"
runat="server"
selectmethod="GetAllEmployees"
typename="Samples.AspNet.CS.EmployeeLogic" />
</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 - Visual Basic Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:gridview
id="GridView1"
runat="server"
datasourceid="ObjectDataSource1" />
<asp:objectdatasource
id="ObjectDataSource1"
runat="server"
selectmethod="GetAllEmployees"
typename="Samples.AspNet.VB.EmployeeLogic" />
</form>
</body>
</html>
Comentários
O método especificado pode ter qualquer assinatura de método, mas deve retornar um dos tipos listados na tabela a seguir para que o ObjectDataSource controle o chame com êxitoThe specified method can have any method signature but must return one of the types listed in the following table in order for the ObjectDataSource control to call it successfully
| Tipo de retornoReturn type | AçãoAction |
|---|---|
| IEnumerable | O IEnumerable é retornado pelo Select método.The IEnumerable is returned by the Select method. |
| DataTable | Um DataView é criado usando o DataTable e retornado pelo Select método.A DataView is created using the DataTable and returned by the Select method. |
| DataSet | O primeiro DataTable de DataSet é extraído e um DataView é criado e retornado pelo Select método.The first DataTable of the DataSet is extracted and a DataView is created and returned by the Select method. |
| Object | O objeto é encapsulado em um elemento de um IEnumerable e retornado pelo Select método.The object is wrapped in a one-element IEnumerable and returned by the Select method. |
O método identificado pela SelectMethod propriedade pode ser um método de instância ou um método static ( Shared no Visual Basic).The method that is identified by the SelectMethod property can be an instance method or a static (Shared in Visual Basic) method. Se for um método de instância, o objeto comercial será criado e destruído cada vez que o SelectMethod método for chamado.If it is an instance method, the business object is created and destroyed each time the SelectMethod method is called. Você pode manipular o ObjectCreated evento para trabalhar com o objeto comercial antes que o método especificado pela SelectMethod propriedade seja chamado.You can handle the ObjectCreated event to work with the business object before the method specified by the SelectMethod property is called. Você também pode manipular o ObjectDisposing evento que é gerado depois que o método especificado pela SelectMethod propriedade é chamado.You can also handle the ObjectDisposing event that is raised after the method specified by the SelectMethod property is called. ( Dispose será chamado somente se o objeto comercial implementar a IDisposable interface.) Se o método for um static Shared método (no Visual Basic), o objeto comercial nunca será criado e você não poderá manipular esses eventos.(Dispose is called only if the business object implements the IDisposable interface.) If the method is a static (Shared in Visual Basic) method, the business object is never created and you cannot handle these events.
Se o objeto comercial com o qual o ObjectDataSource controle funciona implementa mais de um método ou função com o mesmo nome (sobrecargas de método), o controle da fonte de dados tentará invocar o correto de acordo com um conjunto de condições, incluindo os parâmetros na SelectParameters coleção.If the business object that the ObjectDataSource control works with implements more than one method or function with the same name (method overloads), the data source control attempts to invoke the correct one according to a set of conditions, including the parameters in the SelectParameters collection. Se os parâmetros na SelectParameters coleção não corresponderem aos da assinatura do método especificado pela SelectMethod propriedade, a fonte de dados lançará uma exceção.If the parameters in the SelectParameters collection do not match those of the signature of the method specified by the SelectMethod property, the data source throws an exception.
Para obter mais informações, consulte ObjectDataSource.SelectMethod.For more information, see ObjectDataSource.SelectMethod.