Asp.net objectdatasource TypeName property error

我只是一个虾纸丫 提交于 2019-12-11 02:51:48

问题


I use ASP:ObjectDataSource for grid data binding.

My problem is when I run this code I get error.

<asp:ObjectDataSource ID="odsListing" 
runat = "server"  
SelectMethod = "MethodNameOfCodeBehindClass"
TypeName = "FolderName_CodeBehindClassName" ></asp:ObjectDataSource>

Error message

The type specified in the TypeName property of 
ObjectDataSource 'odsListing' could not be found.

So I move my code to codebehind site.

    #region ObjectDataSource for Grid Binding
    Type type = typeof(FolderName_CodeBehindClassName);
    string assemblyQualifiedName = type.AssemblyQualifiedName;

    odsListing.TypeName = assemblyQualifiedName;
    odsListing.SelectMethod = "ListingDatabind";
    #endregion

Now Everythings is ok. It is work. But I would like to know actual solution for my problem. Why it raise error?

Actually, I don't want to move my code to codebehind layer if it can write at design layer.

Every suggestion will be appreciated.


回答1:


The problem is that you are using short type name instead of full type name.

Replace FolderName_CodeBehindClassName with The.NameSpace.YouHaveYourTypeIn.FolderName_CodeBehindClassName, Name.Of.Your.Assembly.



来源:https://stackoverflow.com/questions/12089488/asp-net-objectdatasource-typename-property-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!