473,385 Members | 1,546 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,385 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
2 1012
please dont crosspost. that is rude

Feb 17 '06 #2
a
Sorry

Paul
--------------------------------------------------

"DKode" wrote:
please dont crosspost. that is rude

Feb 17 '06 #3

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...
0
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 ...
7
by: a | last post by:
If the code to insert a new Student is: Profile.Teachers.Classes.Students.Add(new TCS.Student(id,teacher, class, name)); what is the code to Remove a student? I tried the code below, but I...
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: 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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.