Y
yanni
Hello,
I'm creating asp.net 2.0 web site app, I tried to use ¡°ObjectIssue.Page1¡±
as TypeName of ObjectDataSource, received error message ¡°The type specified
in the TypeName property of ObjectDataSource 'object1' could not be found.¡±,
If I instead use a class in App_Code folder as TypeName, it works find. But
I can¡¯t figure out why it didn¡¯t work for aspx page class?
Here¡¯s the code:
--------- Page1.aspx.cs: ----------
namespace ObjectIssue
{
public partial class Page1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public List<Person> GetPerson()
{
List<Person> pList = new List<Person>();
pList.Add(new Person("James", 27));
return pList;
}
}
public class Person
{
public Person(string sName, int iAge)
{
_name = sName;
_age = iAge;
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
}
}
-------------Page1.aspx:----------------------------------------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs"
Inherits="ObjectIssue.Page1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="object1" runat="server"
TypeName="ObjectIssue.Page1" SelectMethod="GetPerson" />
<asp:FormView ID="formView1" runat="server" DataSourceID="object1">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
I'm creating asp.net 2.0 web site app, I tried to use ¡°ObjectIssue.Page1¡±
as TypeName of ObjectDataSource, received error message ¡°The type specified
in the TypeName property of ObjectDataSource 'object1' could not be found.¡±,
If I instead use a class in App_Code folder as TypeName, it works find. But
I can¡¯t figure out why it didn¡¯t work for aspx page class?
Here¡¯s the code:
--------- Page1.aspx.cs: ----------
namespace ObjectIssue
{
public partial class Page1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public List<Person> GetPerson()
{
List<Person> pList = new List<Person>();
pList.Add(new Person("James", 27));
return pList;
}
}
public class Person
{
public Person(string sName, int iAge)
{
_name = sName;
_age = iAge;
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
}
}
-------------Page1.aspx:----------------------------------------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs"
Inherits="ObjectIssue.Page1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="object1" runat="server"
TypeName="ObjectIssue.Page1" SelectMethod="GetPerson" />
<asp:FormView ID="formView1" runat="server" DataSourceID="object1">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>