4

I am using visual studio 2008, i included a class in the AppCode folder and wated to use its functions in ObjectDataSource.

Genius
  • 1,084
  • 2
  • 10
  • 20
  • I know this is old, but I had a similar problem. My problem was with a website project. I always forget what the problem is, but for me I had to make sure the website was using Visual Studio's web server and not IIS. Had to close and then re-open visual studio. Not sure if the same applies to a website solution. – pqsk Jul 23 '13 at 16:15

9 Answers9

2

In aspx

<asp:GridView ID="GridView1" 
     AutoGenerateColumns="true" 
     DataSourceID="ObjectDataSource1" runat="server">
</asp:GridView>

<asp:ObjectDataSource ID="ObjectDataSource1"
     SelectMethod="GetCustomers"
     TypeName="MyNamespace.CustomerManager"
     runat="server"></asp:ObjectDataSource>

In .cs (inside App_Code)

namespace MyNamespace
{
    public class Customer
    {
        public string Name { get; set; }
    }

    public class CustomerManager
    {
        public List<Customer> GetCustomers()
        {
            List<Customer> cust = new List<Customer>();
            Customer c = new Customer();
            c.Name = "sampleName";
            cust.Add(c);
            return cust;
        }
    }
}

After this I was able to see the Customer details in the GridView.

dhinesh
  • 4,676
  • 2
  • 26
  • 44
1

Mouldy oldie Q&A but I just happened to stumble on this thread while wracking my brain on this issue. My solution was to ensure the related classes are all public.

TonyG
  • 1,432
  • 12
  • 31
1

You can always manually type in the object's name into the objectDatasource, in the format of:

namespace.classname, App_Code

App_Code works for web site projects; otherwise, specify the name of the assembly of the web project if the web application project template.

HTH.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • Buddy, its already in the same assembly, then also its not showing up – Genius Oct 29 '10 at 13:43
  • 1
    Dude, sometimes the designer doesn't work, but if you type in the name, the other features like the methods to setup for selecting, inserting, etc. Otherwise, you might have to manually add it all in... If you are using web site project, you have to refer to the assembly as App_Code, but you don't do that if it's a web app project. – Brian Mains Oct 29 '10 at 17:04
1

You might need to mark your class and methods with some attributes for them to show up in the designer. Look at DataObject and DataObjectMethod.

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
batwad
  • 3,588
  • 1
  • 24
  • 38
1

If you have tried all the above, then its your machine issue may be your machine do not support that.

4b0
  • 21,981
  • 30
  • 95
  • 142
Subodh Bansal
  • 385
  • 1
  • 4
  • 12
1

I had the same problem, ended up fixing by adding App_Code to TypeName... simple fix but took a lot of time to realize it. (From example)

<asp:ObjectDataSource ID="ObjectDataSource1"
     SelectMethod="GetCustomers"
     TypeName="MyNamespace.App_Code.CustomerManager"
     runat="server">
</asp:ObjectDataSource>
Christian Specht
  • 35,843
  • 15
  • 128
  • 182
Rabidwolff
  • 11
  • 1
  • It's not the folder location per se, but rather the namespace. By convention, they're the same, but not necessarily. Ultimately, it's the fact that that was the correct namespace that made it work, not the fact that it was in that folder. – as9876 Jul 20 '15 at 17:26
0

Maybe you are opening as "Project" instead of "Website", I do not know why the Data Object does not shows me when is opened as "Project".

  • I can see that this was your first answer to a question, so you didn't have the rep to post this as a comment, but in the future, you might want to consider posting this as a comment. Answers are supposed to be a solution to the problem that you are pretty confident will solve the problem. – Fluffeh Sep 28 '12 at 11:00
0

I was directed to this question because I had a similar issue. My resolution came from the following answer, provided by StevenMcD:

Right click on the .cs file in the App_Code folder and check its properties.

Make sure the "Build Action" is set to "Compile".

Classes residing in App_Code is not accessible

Community
  • 1
  • 1
Jason D.
  • 390
  • 3
  • 11
0

Check you web.config file for VS entries such as sections that might cause this issue (remove entries and rebuild).