Reputation: 1114
I am using visual studio 2008, i included a class in the AppCode folder and wated to use its functions in ObjectDataSource.
Upvotes: 4
Views: 9893
Reputation: 3655
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.
Upvotes: 1
Reputation: 1
Check you web.config file for VS entries such as sections that might cause this issue (remove entries and rebuild).
Upvotes: 0
Reputation: 480
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
Upvotes: 0
Reputation: 1538
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.
Upvotes: 1
Reputation: 385
If you have tried all the above, then its your machine issue may be your machine do not support that.
Upvotes: 1
Reputation: 11
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".
Upvotes: 0
Reputation: 11
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>
Upvotes: 1
Reputation: 4764
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.
Upvotes: 3
Reputation: 50728
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.
Upvotes: 1