編輯

共用方式為


ObjectDataSourceView.TypeName Property

Definition

Gets or sets the name of the class that the ObjectDataSource control represents.

public:
 property System::String ^ TypeName { System::String ^ get(); void set(System::String ^ value); };
public string TypeName { get; set; }
member this.TypeName : string with get, set
Public Property TypeName As String

Property Value

A partially or fully qualified class name that identifies the type of the object that the ObjectDataSource represents. The default is an empty string.

Examples

The following code example demonstrates how a GridView control can display data using an ObjectDataSource control on a Web Forms page. 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. At run time, the object is created and the method is called using reflection. The GridView control enumerates through the IEnumerable collection that is returned by the SelectMethod and 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>

Remarks

To create an instance of the object that the ObjectDataSource control binds to, the control uses reflection to load the type that is identified by the type name at run time. Therefore, the value of the TypeName property can be a partially qualified type for code that is located in the Bin or App_Code directory or a fully qualified type name for code that is registered in the global assembly cache. If you use the global assembly cache, you must add the appropriate reference to the assemblies section of the Machine.config or Web.config configuration file.

Applies to