Why can¡¯t I use an aspx page class as TypeName for ObjectDataSource?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yanni

    Why can¡¯t I use an aspx page class as TypeName for ObjectDataSource?

    Hello,



    I'm creating asp.net 2.0 web site app, I tried to use ¡°ObjectIssue.P age1¡±
    as TypeName of ObjectDataSourc e, received error message ¡°The type specified
    in the TypeName property of ObjectDataSourc e '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.P age

    {

    protected void Page_Load(objec t sender, EventArgs e)

    {

    }



    public List<PersonGetP erson()

    {

    List<PersonpLis t = 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="Objec tIssue.Page1" %>



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">



    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitl ed Page</title>

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <asp:ObjectData Source ID="object1" runat="server"
    TypeName="Objec tIssue.Page1" SelectMethod="G etPerson" />

    <asp:FormView ID="formView1" runat="server" DataSourceID="o bject1">

    <ItemTemplate >

    <%# Eval("Name") %>

    </ItemTemplate>

    </asp:FormView>

    </div>

    </form>

    </body>

    </html>



  • Alexey Smirnov

    #2
    =?ISO-8859-1?Q?Re=3A_Why_c an=A1=AFt_I_use _an_aspx_page_c lass_as_TypeNam ?==?ISO-8859-1?Q?e_for_Objec tDataSource=3F? =

    On Nov 8, 5:35 pm, "yanni" <yanni6...@126. comwrote:
    Hello,
    >
    I'm creating asp.net 2.0 web site app, I tried to use ¡°ObjectIssue.P age1¡±
    as TypeName of ObjectDataSourc e, received error message ¡°The type specified
    in the TypeName property of ObjectDataSourc e '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.P age
    >
        {
    >
            protected void Page_Load(objec t sender, EventArgs e)
    >
            {
    >
            }
    >
            public List<PersonGetP erson()
    >
            {
    >
                List<PersonpLis t = 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="Objec tIssue.Page1" %>
    >
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    >
    <html xmlns="http://www.w3.org/1999/xhtml" >
    >
    <head runat="server">
    >
        <title>Untitl ed Page</title>
    >
    </head>
    >
    <body>
    >
        <form id="form1" runat="server">
    >
        <div>
    >
            <asp:ObjectData Source ID="object1" runat="server"
    TypeName="Objec tIssue.Page1" SelectMethod="G etPerson" />
    >
            <asp:FormView ID="formView1" runat="server" DataSourceID="o bject1">
    >
                <ItemTemplate >
    >
                    <%# Eval("Name") %>
    >
                </ItemTemplate>
    >
            </asp:FormView>
    >
        </div>
    >
        </form>
    >
    </body>
    >
    </html>
    this works to me

    Comment

    Working...