473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.Collections.ArrayList" serializeAs="Xml"
allowAnonymous="true"/>

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

protected void Button1_Click(object 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.Students.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.Students.Add(teacher.Students[3]);

teacher.Students.Add(teacher.Students[5]);

teacher.Students.Add(teacher.Students[9]);

}

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

teachers.Add(teacher);

// 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.Teachers'(ie Profile.Teachers)

Profile.Teachers.Add((School.Teacher[])teachers.ToArray(typeof(School.Teacher)));

}

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

using System;

using System.Collections;

using System.Xml.Serialization;// 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 currentGradeLevel;

#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 CurrentGradeLevel

{

get { return this.currentGradeLevel; }

set { this.currentGradeLevel = 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
CurrentGradeLevel)

{

this.id = Id;

this.firstName = FirstName;

this.lastName = LastName;

this.gPA = GPA;

this.currentGradeLevel = CurrentGradeLevel;

}

#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(value);

}

public void Insert(int index, Student value)

{

List.Insert(index, value);

}

public void Remove(Student value)

{

List.Remove(value);

}

public bool Contains(Student value)

{

return List.Contains(value);

}

#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,DateTime 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(value);

}

public void Insert(int index, sClass value)

{

List.Insert(index, value);

}

public void Remove(sClass value)

{

List.Remove(value);

}

public bool Contains(sClass value)

{

return List.Contains(value);

}

#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(value);

}

public void Insert(int index, Teacher value)

{

List.Insert(index, value);

}

public void Remove(Teacher value)

{

List.Remove(value);

}

public bool Contains(Teacher value)

{

return List.Contains(value);

}

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

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

public Teachers() { }

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

}

}
Feb 17 '06 #1
0 1800

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

Similar topics

2
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...
6
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...
0
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...
0
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...
0
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...
0
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...
8
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...
2
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 ...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.