473,383 Members | 1,829 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,383 software developers and data experts.

How do I retreive a custom object's properties from an arraylist

Ric
Please forgive me if i dont explain this situation correctly. i'll try
to do my best.

because the arraylist.add method only accepts one argument, i created
an object with several public properties.

AddElement.vb (compiled and saved in Bin folder)
' VB Document
Imports System

Namespace myArrayObject

Public Class AddElement
Private _pName as String
Private _pType as String
Private _pSize as Integer

Public Property pName as String
Get
Return _pName
End Get
Set
_pName = Value
End Set
End Property

Public Property pType as String
Get
Return _pType
End Get
Set
_pType = Value
End Set
End Property

Public Property pSize as Integer
Get
Return _pSize
End Get
Set
_pSize = Value
End Set
End Property

End Class
End Namespace

Then I imported this object into a codebehind file. my goal was to
instiate the object's properties and set them accordingly

dbArraylist.vb (codebehind file with command event sub)

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HTMLControls
Imports myArrayObject
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports dbComponent

public class myALComponent
Inherits Page
Protected WithEvents lkID as linkbutton, lblAnswer as label
sub getActivityList(s as Object, e as CommandEventArgs)

Dim ID As Int32 = Int32.Parse(e.CommandArgument)

Dim myArrayList as new ArrayList, myParameter as new AddElement,
objItem as object
myParameter.pName = "@ID"
myParameter.pType = "ID"
myParameter.pSize = 0
myArrayList.add(myParameter)

myParameter.pName = "@ID2"
myParameter.pType = "ID2"
myParameter.pSize = 2
myArrayList.add(myParameter)

response.write("<br>myArrayList Count : "& myArrayList.count &
"<br>")

for each objItem in myArrayList
response.write("<br>AL : <br><li>" & objItem.toString)
next
end sub
end class

the aspx file passes the commandName and commandargument (= 1) via a
linkbutton. ive tested the link and it works, but im not using the
commandargument yet. my obstacle now is retreiving the property values
stored inside the object inside the arraylist. right now, i get
'myArrayObject.AddElement' as the objItem in myArrayList. that makes
sense because that is the object inside the arraylist. but, i want to
get the pName(string), pType(string) and pSize(integer) which are
public properties of the AddElement object from the
myArrayList(elementNumber). i tried casting it toString (result :
myArrayObject.Addelement) and cType(myArrayList(0), string) result :
can not cast error. thx for the help in advance.

ric
Nov 18 '05 #1
2 1699
Hi, Ric,

Try to cast the elements of the ArrayList to the type of your class, i.e.

Response.Write(CType(myArrayList(0), AddElement).pName)

Hope thid helps
Martin
"Ric" <dj****************@yahoo.com> wrote in message
news:78**************************@posting.google.c om...
Please forgive me if i dont explain this situation correctly. i'll try
to do my best.

because the arraylist.add method only accepts one argument, i created
an object with several public properties.

AddElement.vb (compiled and saved in Bin folder)
' VB Document
Imports System

Namespace myArrayObject

Public Class AddElement
Private _pName as String
Private _pType as String
Private _pSize as Integer

Public Property pName as String
Get
Return _pName
End Get
Set
_pName = Value
End Set
End Property

Public Property pType as String
Get
Return _pType
End Get
Set
_pType = Value
End Set
End Property

Public Property pSize as Integer
Get
Return _pSize
End Get
Set
_pSize = Value
End Set
End Property

End Class
End Namespace

Then I imported this object into a codebehind file. my goal was to
instiate the object's properties and set them accordingly

dbArraylist.vb (codebehind file with command event sub)

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HTMLControls
Imports myArrayObject
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports dbComponent

public class myALComponent
Inherits Page
Protected WithEvents lkID as linkbutton, lblAnswer as label
sub getActivityList(s as Object, e as CommandEventArgs)

Dim ID As Int32 = Int32.Parse(e.CommandArgument)

Dim myArrayList as new ArrayList, myParameter as new AddElement,
objItem as object
myParameter.pName = "@ID"
myParameter.pType = "ID"
myParameter.pSize = 0
myArrayList.add(myParameter)

myParameter.pName = "@ID2"
myParameter.pType = "ID2"
myParameter.pSize = 2
myArrayList.add(myParameter)

response.write("<br>myArrayList Count : "& myArrayList.count &
"<br>")

for each objItem in myArrayList
response.write("<br>AL : <br><li>" & objItem.toString)
next
end sub
end class

the aspx file passes the commandName and commandargument (= 1) via a
linkbutton. ive tested the link and it works, but im not using the
commandargument yet. my obstacle now is retreiving the property values
stored inside the object inside the arraylist. right now, i get
'myArrayObject.AddElement' as the objItem in myArrayList. that makes
sense because that is the object inside the arraylist. but, i want to
get the pName(string), pType(string) and pSize(integer) which are
public properties of the AddElement object from the
myArrayList(elementNumber). i tried casting it toString (result :
myArrayObject.Addelement) and cType(myArrayList(0), string) result :
can not cast error. thx for the help in advance.

ric

Nov 18 '05 #2


thx again martin for the quick help. it worked perfectly.

ric

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

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

Similar topics

8
by: Joe | last post by:
I have several classes which I need serialized. Here is their class definitions: public class TopContainer { private LevelTwoType m_levelTwo; public LevelTwoType LevelTwo { get {
2
by: raymi | last post by:
Hi, I have a custom class that gets its properties dynamically from a database at runtime. Therefore I implemented the ICustomTypeDescriptor in this class and created a a custom...
1
by: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar...
6
by: Whoever | last post by:
Here's what I have A custom collection: public class aUser { public string UserName { get {...} set {...} } public class UserList : System.Collection.CollectionBase { public void Add(aUser...
4
by: eugenet | last post by:
Hello, I am writing a Windows Forms application using .NET Framework 2.0 and Visual Studio 2005. I would like to use Properties.Settings class to persist a collection of custom objects. For...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
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 ...
0
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
4
by: Jon Paal | last post by:
I have a custom server control which renders some html. I want to capture some interim values generated by the control as it processes the data. is there a way to capture and retrieve the...
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...
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...
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: 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?

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.