I am using visual studio 2008, i included a class in the AppCode folder and wated to use its functions in ObjectDataSource.
-
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– pqsk2013-07-23 16:15:34 +00:00Commented Jul 23, 2013 at 16:15
9 Answers
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.
Comments
If you have tried all the above, then its your machine issue may be your machine do not support that.
1 Comment
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.
2 Comments
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>
1 Comment
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.
Comments
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".
1 Comment
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".