Asp.net objectdatasource TypeName property error
Asked Answered
D

1

2

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.

Desirous answered 23/8, 2012 at 10:19 Comment(0)
A
4

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.

Adactylous answered 23/8, 2012 at 10:24 Comment(2)
I am using ASP.NET Web Site which has no assembly and even no namespace have. So how could I do it please ?Desirous
Omit the assembly. However, I am almost sure that your class is in some namespace. The problem with VB is that even if you don't have namespace in code, there's the default namespace. Take a look at project properties and find a textbox "default namespace".Adactylous

© 2022 - 2024 — McMap. All rights reserved.