ObjectDataSource does not display data objects in data source settings

I am using visual studio 2008, I have included the class in the AppCode folder and used it in ObjectDataSource.

+4
source share
9 answers

If you tried all of the above, then his problem with the machine may be, your machine does not support this.

+1
source

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 that, I was able to see client information in the GridView.

+2
source

You can always manually enter the name of an object in objectDatasource in the format:

namespace.classname, App_Code

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

NTN.

+1
source

You may need to mark your class and methods with some attributes to display them in the constructor. Take a look at DataObject and DataObjectMethod .

+1
source

I had the same problem, the result was fixed by adding App_Code to TypeName ... a simple fix, but it took a long time to figure this out. (From an example)

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

Lightning old Q & A, but I just accidentally stumbled upon this topic, waving brains on this issue. My solution was to ensure that related classes are publicly accessible.

+1
source

Perhaps you open as “Project” instead of “Website,” I don’t know why the Data object does not show me when it opens as “Project”.

0
source

I was directed to this question because I had a similar problem. My solution was obtained from the following answer provided by StevenMcD:

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

Make sure Build Action is set to Compile.

Classes in App_Code are not available

0
source

Check the web.config file for VS entries, such as partitions, that may cause this problem (delete entries and rebuild).

0
source

All Articles