473,767 Members | 2,166 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
2 1027
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
1977
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
2227
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 and we have Profile property for pages that could be extended with configuration to have custom...
0
1685
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 set of profiles. - FindInactiveProfilesByUserName. Returns a collection of ProfileInfo
0
2571
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
1170
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? Whatever the answer is, I'm trying to learn what I need to do to get my custom object to bind to...
0
1955
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 code----------------------------------------------------------------------------------
8
2020
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>
0
1836
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. The aspx code below shows the attempt and error message.
7
1691
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 don't understand the syntax: Profile.Teachers.Classes.Students.Remove(new TCS.Student(name));// This line fails
0
1426
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 - PropertyValuesBinary column). But, when I want to read the information in the profile, my custom type object is...
0
9571
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10009
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9838
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
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
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.