ObjectDataSourceView.TypeName 属性

定义

获取或设置 ObjectDataSource 控件表示的类的名称。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

属性值

String

标识 ObjectDataSource 表示的对象类型的部分或完全限定类名。A partially or fully qualified class name that identifies the type of the object that the ObjectDataSource represents. 默认值为一个空字符串。The default is an empty string.

示例

下面的代码示例演示控件如何 GridView 使用 ObjectDataSource Web 窗体页上的控件来显示数据。The following code example demonstrates how a GridView control can display data using an ObjectDataSource control on a Web Forms page. ObjectDataSource标识部分或完全限定类名及其 TypeName 属性和调用以检索数据及其属性的方法 SelectMethodThe 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. GridView控件枚举 IEnumerable 返回的集合, SelectMethod 并显示数据。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>

注解

若要创建控件绑定到的对象的实例 ObjectDataSource ,控件将使用反射来加载运行时由类型名称标识的类型。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. 因此,属性的值 TypeName 可以是位于 Bin 或 App_Code 目录中的代码的部分限定类型,也可以是在全局程序集缓存中注册的代码的完全限定类型名称。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. 如果使用全局程序集缓存,则必须将相应的引用添加到 assemblies Machine.config 的节或 Web.config 配置文件中。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.

适用于