473,544 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Object and Profile Object

a
I need to create an instance of a custom object 'School.Teacher ' and use it
in a Profile object.

I'm developing a bad case of "Pretzel Logic" thinking about this.

Filling the custom object 'School.Teacher ' as an ArrayList creates the
proper information (see aspx code below), but I'm unable to use this
ArrayList in the Profile object. The aspx code below shows the attempt and
error message.

Any ideas?

-----------------------------------------------------------------------------------------------------------------------------------

The Custom object 'School.Teacher ' is in Section 3 on this page

Section 1 =============== =============== =============== ====== web.config
Profile property

<add name="School" type="System.Co llections.Array List" serializeAs="Xm l"
allowAnonymous= "true"/>

Section 2 =============== =============== =============== ====== aspx code

protected void Button1_Click(o bject sender, EventArgs e)

{

//School.Teacher is a SINGLE object, NOT a collection.

ArrayList teachers = new ArrayList(); // Create a new ArrayList

// Add
Teacher-------------------------------------------------------------------------

School.Teacher teacher = new School.Teacher( "Marc"); // Create a new Teacher

// Add 10 students to the
teacher------------------------------------------------------

for (int i = 0; i < 10; i++)

{

teacher.Student s.Add(new School.Student( "Student " + i.ToString()));

}

// Add Classes
------------------------------------------------------------------------

// Create 5 classes for this teacher AND add students 4,6 and 10 to each
class.

for (int i = 0; i < 5; i++)

{

School.sClass newClass = new School.sClass(" Class " + i.ToString());

teacher.Classes .Add(newClass);

teacher.Student s.Add(teacher.S tudents[3]);

teacher.Student s.Add(teacher.S tudents[5]);

teacher.Student s.Add(teacher.S tudents[9]);

}

// Add this teacher(that now has classes and students) to the teachers
ArrayList

teachers.Add(te acher);

// Return 'teachers' array of the type School.Teacher[] (cast from the type
'School.Teacher ')

// This equation raise the cast error:

// Can't cast 'School.Teacher[]' to 'School.Teacher s'(ie Profile.Teacher s)

Profile.Teacher s.Add((School.T eacher[])teachers.ToArr ay(typeof(Schoo l.Teacher)));

}

Section 3 =============== =============== =============== ============ Custom
Object

using System;

using System.Collecti ons;

using System.Xml.Seri alization;// need for 'Teacher Students Property'
decoration

namespace School

{

#region Student
Object+++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++

[Serializable()]

public class Student

{

#region Private members (Fields) +++++++++++++++ +++++

int id;

string firstName;

string lastName;

int gPA;

int currentGradeLev el;

#endregion -------------------------------------------

#region Public Accessors (Properties) ++++++++++++++

public int Id

{

get { return this.id; }

set { this.id = value; }

}

public string FirstName

{

get { return this.firstName; }

set { this.firstName = value; }

}

public string LastName

{

get { return this.lastName; }

set { this.lastName = value; }

}

public int GPA

{

get { return this.gPA; }

set { this.gPA = value; }

}

public int CurrentGradeLev el

{

get { return this.currentGra deLevel; }

set { this.currentGra deLevel = value; }

}

#endregion -------------------------------------------

#region Constructors +++++++++++++++ +++++++++++++++ +++

// Empty constructor

public Student()

{ }

// Partial Constructor

public Student(string FirstName)

{

this.firstName = FirstName;

}

// Full Constructor

public Student(int Id, string FirstName, string LastName, int GPA, int
CurrentGradeLev el)

{

this.id = Id;

this.firstName = FirstName;

this.lastName = LastName;

this.gPA = GPA;

this.currentGra deLevel = CurrentGradeLev el;

}

#endregion -------------------------------------------

}

#endregion

[Serializable()]

public class Students : CollectionBase

{

#region Public Accessors (Properties) ++++++++++++++

public Student this[int index]

{

set

{

List[index] = value;

}

get

{

return (Student)List[index];

}

}

public int Add(Student value)

{

return List.Add(value) ;

}

public int IndexOf(Student value)

{

return List.IndexOf(va lue);

}

public void Insert(int index, Student value)

{

List.Insert(ind ex, value);

}

public void Remove(Student value)

{

List.Remove(val ue);

}

public bool Contains(Studen t value)

{

return List.Contains(v alue);

}

#endregion -------------------------------------------

#region Constructors +++++++++++++++ +++++++++++++++ +++

public Students()

{ }

#endregion -------------------------------------------

}



#region sClass
Object+++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++

[Serializable()]

public class sClass

{

#region Private members (Fields) +++++++++++++++ +++++

private string className;

private DateTime startTime;

private DateTime endTime;

#endregion -------------------------------------------

#region Public Accessors (Properties) ++++++++++++++

public string Name

{

get { return className; }

set { className = value; }

}

public DateTime StartTime

{

get { return this.startTime; }

set { this.startTime = value; }

}

public DateTime EndTime

{

get { return this.endTime; }

set { this.endTime = value; }

}

#endregion -------------------------------------------

#region Constructors +++++++++++++++ +++++++++++++++ +++

// empty constructor

public sClass()

{ }

// Partial Constructor1

public sClass(string ClassName)

{

this.className = ClassName;

}

// Full Constructor

public sClass(string ClassName,DateT ime StartTime, DateTime EndTime)

{

this.className = ClassName;

this.startTime = StartTime;

this.endTime = EndTime;

}

#endregion -------------------------------------------

}

#endregion

[Serializable()]

public class Classes : CollectionBase

{

public sClass this[int index]

{

set

{

List[index] = value;

}

get

{

return (sClass)List[index];

}

}

#region Public Accessors (Properties) ++++++++++++++

public int Add(sClass value)

{

return List.Add(value) ;

}

public int IndexOf(sClass value)

{

return List.IndexOf(va lue);

}

public void Insert(int index, sClass value)

{

List.Insert(ind ex, value);

}

public void Remove(sClass value)

{

List.Remove(val ue);

}

public bool Contains(sClass value)

{

return List.Contains(v alue);

}

#endregion -------------------------------------------

#region Constructors +++++++++++++++ +++++++++++++++ +++

public Classes()

{ }

#endregion -------------------------------------------

}



#region Teacher
Object+++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++

[Serializable()]

public class Teacher

{

#region Private members (Fields) +++++++++++++++ +++++

private string name;

School.Classes classes = new School.Classes( );

School.Students students = new School.Students ();

#endregion -------------------------------------------

#region Public Accessors (Properties) ++++++++++++++

public string Name

{

get { return name; }

set { name = value; }

}

public School.Classes Classes

{

get { return this.classes; }

set { this.classes = value; }

}

//[XmlIgnore] // XmlIgnore is need for proper nesting of the xml output

public School.Students Students

{

get { return this.students; }

set { this.students = value; }

}

#endregion -------------------------------------------

#region Constructors +++++++++++++++ +++++++++++++++ +++
public Teacher()

{ }

public Teacher(string name)

{

this.name = Name;

}

public Teacher(string Name, School.Classes Classes)

{

this.name = Name;

this.classes = Classes;

}

public Teacher(string Name, School.Classes Classes, School.Students Students)

{

this.name = Name;

this.classes = Classes;

this.students = Students;

}

#endregion -------------------------------------------

}

#endregion

[Serializable()]

public class Teachers : CollectionBase

{

#region Private members (Fields) +++++++++++++++

#endregion --------------------------------------

#region Indexer +++++++++++++++ +++++++++++++++ +++

public Teacher this[int index]

{

set

{

List[index] = value;

}

get

{

return (Teacher)List[index];

}

}

#endregion ------------------------------------

#region Public Accessors (Properties) ++++++++++++++

public int Add(Teacher value)

{

return List.Add(value) ;

}

public int IndexOf(Teacher value)

{

return List.IndexOf(va lue);

}

public void Insert(int index, Teacher value)

{

List.Insert(ind ex, value);

}

public void Remove(Teacher value)

{

List.Remove(val ue);

}

public bool Contains(Teache r value)

{

return List.Contains(v alue);

}

#endregion -------------------------------------------

#region Constructors +++++++++++++++ +++++++++++++++ +++

public Teachers() { }

#endregion -------------------------------------------

}

}
Feb 17 '06 #1
0 1822

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1965
by: | last post by:
Hi all, How can I get a reference to my custom profile provider in my .aspx page? I have looked at httpcontext.current.profile. But from there where do I go? Ideally I would like to be able to get default profile provider without having to know the "name" configured in web.config. TIA!
6
2211
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base class would have CurrentUser property that would hold customer class in session and that was fine for all my situations. Now ASP.NET 2.0 came...
0
1666
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a specified date. - DeleteProfile. Enables you to delete a profile associated with a specified username. - DeleteProfiles. Enables you to delete a...
0
2551
by: Giorgio | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a specified date. - DeleteProfile. Enables you to delete a profile associated with a
0
1159
by: a | last post by:
I have a custom object that inherits from CollectionBase and it does not successfully bind to GridViews or DropdownLists. My understanding is that that is because GridViews and Dropdownlists implement IEnumerable, therefore, if I want my custom object to bind to the gridview or the dropdownlist, I need to inherit from IEnumerable also, right?...
0
1942
by: a | last post by:
Q. Unable to get a Profile custom (object) collection to bind to GridView,etc (IList objects)? This is my first custom object so I may be doing something rather simple, wrong, or it may be something else to do with the Profile object. Either way, I need help Here's a brief description of the...
8
2012
by: a | last post by:
I'm trying to save data from a custom object into the profile object, but it is not structured the way that I want. I'm trying to get the custom object to serialize as xml to a Profile object like so: <Teachers> <Teacher> <Classes> <Class>
2
1021
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object 'School.Teacher' as an ArrayList creates the proper information (see aspx code below), but I'm unable to use this ArrayList in the Profile object....
0
1411
by: Rajesh | last post by:
I am trying to use a simple custom type for saving the profile information of a user. The custom class inherits from the Hashtable. I am serializing the type as "Binary" in the provider sections of the web.config. When I add a key-value to the custom type, I can see that its being saved in the database (aspnet_profiles table -...
0
7361
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7601
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7763
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7701
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5289
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1834
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
654
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.