【问题标题】:The type specified in the TypeName property of ObjectDataSource 'ObjectDataSource1' could not be found找不到 ObjectDataSource 'ObjectDataSource1' 的 TypeName 属性中指定的类型
【发布时间】:2013-01-03 08:17:38
【问题描述】:

我正在使用 VS2008.Net Framework 3.5,我从 File->New->Web Site 创建了一个站点,我添加了母版页和默认内容页。我添加了对象DetailsViewObjectDataSource。为了在 App_Code 文件夹中填充数据,我创建了三个类, db(连接到 db 并填充表、数据集和数据读取器等) 屏幕(模型类) ScreenDALC(数据访问层类) 请注意,文件后面的所有代码都不在任何特定的命名空间中

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
AllowPaging="True" AutoGenerateRows="False" DataSourceID="ObjectDataSource1">
<Fields>
    <asp:BoundField DataField="ScreenID" HeaderText="ScreenID" 
    SortExpression="ScreenID" />
    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
    ShowInsertButton="True" />
</Fields>
</asp:DetailsView>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
DataObjectTypeName="Screen" DeleteMethod="Delete" 
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 
SelectMethod="GetScreen" TypeName="ScreenDALC" UpdateMethod="Update">
</asp:ObjectDataSource>

当我运行应用程序时,它运行时没有错误,我可以在表单上看到数据。但是当我打开带有http://localhost/irfu/irfulabs/newcpanel/default.aspx 之类的网址的页面时,我会收到主题中的错误消息。

还请注意,我已经尝试过,我将整个项目放在一个命名空间中并收到相同的错误消息,我将所有文件放在一个文件夹中但仍然收到相同的错误消息。我还添加了 System.ComponentModel;为所有方法添加签名。

【问题讨论】:

  • 你的代码是否有一个ScreenDALC 可以被ObjectDataSource1 访问的类?
  • 是的,我在 App_Code 文件夹中有 ScreenDALC 类,但我不知道如何验证它是否可以被 OjectctDataSource 访问,类可以在页面文件后面的代码中访问,如果我运行它也可以正常工作项目,但通过 url 打开时出错
  • 很可能您必须使用其全名指定类型,包括命名空间。这类似于The.Namespace.ScreenDALC。还要确保类型是公开的。

标签: c# objectdatasource


【解决方案1】:

由于代码没有问题,在我的虚拟主机上设置应用程序文件夹和虚拟目录后,错误删除,页面打开成功。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 2018-09-24
    • 2022-01-18
    相关资源
    最近更新 更多