473,791 Members | 2,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I bind/present several Arraylists to a WebForm?

Hi!

I have a problem, I'm not sure if this is the proper way to do it, but I
have the following scenario:
I want to list all categories, and all products in that category whenever I
select a topcategory in a menu.

Example:

- Music
- pop < ------pressing this menuitem should give following result:

CDs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion

DVDs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion

LPs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
I've done this so far, ( se code below )
here I will get the arraylist printed the following way:

For i = 0 To arrProducts.Cou nt - 1
Response.Write( arrProducts(i). ProductID & " -")
Response.Write( arrProducts(i). ProductName & "-")
Response.Write( arrProducts(i). ProductDescript ion & "<br>")
Next

but as you know Response.Write isn't the way to do it :-)
I need some help binding this to a webForm. Would really like to bind this
to a table or anything more structured....
(working in VB and CodeBehind)

'Code behind start********** *************** *************** *************** ***

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
LoopCategories( )
End Sub

Sub LoopCategories( )
Dim CategoryName As String, arrProducts As ArrayList
Dim Conn As New SqlConnection(v ariables.ConnSt ring)
Dim Cmd As New SqlCommand("SEL ECT * FROM tblCategory WHERE Parent =
'376' ", Conn)
Cmd.Connection. Open()
Dim dr As SqlDataReader = Cmd.ExecuteRead er
While dr.Read

CategoryName = dr.Item("name")
arrProducts = GetProducts(dr. Item("CatID"))

'Here I have put the Categoryname in a varable named: CategoryName
'And an arraylist containing all products in this spesific Category

End While
Cmd.Connection. Close()
Cmd.Dispose()
Conn.Dispose()
End Sub

Function GetProducts(ByV al inputCatID As Integer) As ArrayList
Dim arrProducts As New ArrayList()
Dim ConnProducts As New SqlConnection(v ariables.ConnSt ring)
Dim CmdProducts As New SqlCommand("SEL ECT * FROM tblArticle WHERE
CatID = @CatID", ConnProducts)
CmdProducts.Con nection.Open()
CmdProducts.Par ameters.Add(New SqlParameter("@ CatID", inputCatID))
Dim dr As SqlDataReader = CmdProducts.Exe cuteReader
While dr.Read
arrProducts.Add (New ProductItem(dr. Item("ArtID"),
dr.Item("title" ), dr.Item("ingres s")))
End While
CmdProducts.Con nection.Close()
CmdProducts.Dis pose()
ConnProducts.Di spose()
Return arrProducts
End Function
Friend Class ProductItem

Sub New(ByVal ID As Integer, ByVal Name As String, ByVal Description
As String)
ProductID = ID
ProductName = Name
ProductDescript ion = Description
End Sub

Dim _ProductID As Integer
Public Property ProductID() As Integer
Get
Return _ProductID
End Get
Set(ByVal Value As Integer)
_ProductID = Value
End Set
End Property

Dim _ProductName As String
Public Property ProductName() As String
Get
Return _ProductName
End Get
Set(ByVal Value As String)
_ProductName = Value
End Set
End Property

Dim _ProductDescrip tion As String
Public Property ProductDescript ion() As String
Get
Return _ProductDescrip tion
End Get
Set(ByVal Value As String)
_ProductDescrip tion = Value
End Set
End Property
End Class

'code behind ends*********** ****
Thanks for any help!!
Morten......
Nov 19 '05 #1
2 1350

use Repeater, DataList, or DataGrid

"Morten Hauge" <mo****@april.n o> wrote in message
news:e1******** ******@TK2MSFTN GP10.phx.gbl...
Hi!

I have a problem, I'm not sure if this is the proper way to do it, but I
have the following scenario:
I want to list all categories, and all products in that category whenever
I select a topcategory in a menu.

Example:

- Music
- pop < ------pressing this menuitem should give following result:

CDs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion

DVDs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion

LPs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
I've done this so far, ( se code below )
here I will get the arraylist printed the following way:

For i = 0 To arrProducts.Cou nt - 1
Response.Write( arrProducts(i). ProductID & " -")
Response.Write( arrProducts(i). ProductName & "-")
Response.Write( arrProducts(i). ProductDescript ion & "<br>")
Next

but as you know Response.Write isn't the way to do it :-)
I need some help binding this to a webForm. Would really like to bind this
to a table or anything more structured....
(working in VB and CodeBehind)

'Code behind
start********** *************** *************** *************** ***

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
LoopCategories( )
End Sub

Sub LoopCategories( )
Dim CategoryName As String, arrProducts As ArrayList
Dim Conn As New SqlConnection(v ariables.ConnSt ring)
Dim Cmd As New SqlCommand("SEL ECT * FROM tblCategory WHERE Parent =
'376' ", Conn)
Cmd.Connection. Open()
Dim dr As SqlDataReader = Cmd.ExecuteRead er
While dr.Read

CategoryName = dr.Item("name")
arrProducts = GetProducts(dr. Item("CatID"))

'Here I have put the Categoryname in a varable named: CategoryName
'And an arraylist containing all products in this spesific Category

End While
Cmd.Connection. Close()
Cmd.Dispose()
Conn.Dispose()
End Sub

Function GetProducts(ByV al inputCatID As Integer) As ArrayList
Dim arrProducts As New ArrayList()
Dim ConnProducts As New SqlConnection(v ariables.ConnSt ring)
Dim CmdProducts As New SqlCommand("SEL ECT * FROM tblArticle WHERE
CatID = @CatID", ConnProducts)
CmdProducts.Con nection.Open()
CmdProducts.Par ameters.Add(New SqlParameter("@ CatID", inputCatID))
Dim dr As SqlDataReader = CmdProducts.Exe cuteReader
While dr.Read
arrProducts.Add (New ProductItem(dr. Item("ArtID"),
dr.Item("title" ), dr.Item("ingres s")))
End While
CmdProducts.Con nection.Close()
CmdProducts.Dis pose()
ConnProducts.Di spose()
Return arrProducts
End Function
Friend Class ProductItem

Sub New(ByVal ID As Integer, ByVal Name As String, ByVal
Description As String)
ProductID = ID
ProductName = Name
ProductDescript ion = Description
End Sub

Dim _ProductID As Integer
Public Property ProductID() As Integer
Get
Return _ProductID
End Get
Set(ByVal Value As Integer)
_ProductID = Value
End Set
End Property

Dim _ProductName As String
Public Property ProductName() As String
Get
Return _ProductName
End Get
Set(ByVal Value As String)
_ProductName = Value
End Set
End Property

Dim _ProductDescrip tion As String
Public Property ProductDescript ion() As String
Get
Return _ProductDescrip tion
End Get
Set(ByVal Value As String)
_ProductDescrip tion = Value
End Set
End Property
End Class

'code behind ends*********** ****
Thanks for any help!!
Morten......

Nov 19 '05 #2
Thanks for a quick answer, yes I have figured out that datagrid,datali stor
repeater is the proper way of doing this,
But I'm not quite sure how I bind a ArrayList to a datagrid...
If theres any other way of doing this, I will be more than glad for some
examples..

Thanks!
Morten

"Sebastian Wojciechowski" <so*****@micros oft.com> skrev i melding
news:uZ******** ******@TK2MSFTN GP12.phx.gbl...

use Repeater, DataList, or DataGrid

"Morten Hauge" <mo****@april.n o> wrote in message
news:e1******** ******@TK2MSFTN GP10.phx.gbl...
Hi!

I have a problem, I'm not sure if this is the proper way to do it, but I
have the following scenario:
I want to list all categories, and all products in that category whenever
I select a topcategory in a menu.

Example:

- Music
- pop < ------pressing this menuitem should give following result:

CDs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion

DVDs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion

LPs
------------------------------------------------------
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
ProductID ProductName ProductDescript ion
I've done this so far, ( se code below )
here I will get the arraylist printed the following way:

For i = 0 To arrProducts.Cou nt - 1
Response.Write( arrProducts(i). ProductID & " -")
Response.Write( arrProducts(i). ProductName & "-")
Response.Write( arrProducts(i). ProductDescript ion & "<br>")
Next

but as you know Response.Write isn't the way to do it :-)
I need some help binding this to a webForm. Would really like to bind
this to a table or anything more structured....
(working in VB and CodeBehind)

'Code behind
start********** *************** *************** *************** ***

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
LoopCategories( )
End Sub

Sub LoopCategories( )
Dim CategoryName As String, arrProducts As ArrayList
Dim Conn As New SqlConnection(v ariables.ConnSt ring)
Dim Cmd As New SqlCommand("SEL ECT * FROM tblCategory WHERE Parent
= '376' ", Conn)
Cmd.Connection. Open()
Dim dr As SqlDataReader = Cmd.ExecuteRead er
While dr.Read

CategoryName = dr.Item("name")
arrProducts = GetProducts(dr. Item("CatID"))

'Here I have put the Categoryname in a varable named: CategoryName
'And an arraylist containing all products in this spesific Category

End While
Cmd.Connection. Close()
Cmd.Dispose()
Conn.Dispose()
End Sub

Function GetProducts(ByV al inputCatID As Integer) As ArrayList
Dim arrProducts As New ArrayList()
Dim ConnProducts As New SqlConnection(v ariables.ConnSt ring)
Dim CmdProducts As New SqlCommand("SEL ECT * FROM tblArticle WHERE
CatID = @CatID", ConnProducts)
CmdProducts.Con nection.Open()
CmdProducts.Par ameters.Add(New SqlParameter("@ CatID", inputCatID))
Dim dr As SqlDataReader = CmdProducts.Exe cuteReader
While dr.Read
arrProducts.Add (New ProductItem(dr. Item("ArtID"),
dr.Item("title" ), dr.Item("ingres s")))
End While
CmdProducts.Con nection.Close()
CmdProducts.Dis pose()
ConnProducts.Di spose()
Return arrProducts
End Function
Friend Class ProductItem

Sub New(ByVal ID As Integer, ByVal Name As String, ByVal
Description As String)
ProductID = ID
ProductName = Name
ProductDescript ion = Description
End Sub

Dim _ProductID As Integer
Public Property ProductID() As Integer
Get
Return _ProductID
End Get
Set(ByVal Value As Integer)
_ProductID = Value
End Set
End Property

Dim _ProductName As String
Public Property ProductName() As String
Get
Return _ProductName
End Get
Set(ByVal Value As String)
_ProductName = Value
End Set
End Property

Dim _ProductDescrip tion As String
Public Property ProductDescript ion() As String
Get
Return _ProductDescrip tion
End Get
Set(ByVal Value As String)
_ProductDescrip tion = Value
End Set
End Property
End Class

'code behind ends*********** ****
Thanks for any help!!
Morten......


Nov 19 '05 #3

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

Similar topics

2
1565
by: kaasztelann | last post by:
I have a DropDownList on my Webform. This list is bounded to DataSet which is populate from database. When load the form, list is filled and all is OK. The problem is, that the list is small (only 3 items), so I want to preserve the list by ViewState (it is on), and want the list to be populated from database only first time (when IsPostBack==false). How to bind this control only once? I have 1 solution which I don't like: If I don't...
3
17765
by: MrMike | last post by:
Hi. I have a dataset on my webform which I successfully fill by calling a Sub that occurs after the Page_Load. My question is - I have a textbox control which I need to populate with the contents of one of the Dataset columns. If I set set the binding properties using the properties window, this isn't successfull since the textbox attempts to bind at page_load, at which time the dataset is not filled. How can I use VB code to specify...
0
1022
by: John A Grandy | last post by:
in ASP.NET 2.0 , what is the best WebForm DataControl to bind to a Hashtable ?
4
2158
by: John Dalberg | last post by:
I noticed the starterkits timetracker & issue tracker load data from a database into custom collections (arraylists) which bind to a datagrid. What are the advantages of using custom collections over simpler objects like datareaders or datatables? John Dalberg
2
9136
by: Sean | last post by:
How does one bind a SortedList to anything. If it cant be done why would anyone ever even use a sortedlist? We are currently (via business objects that use interfaces etc) binding gridviews to List<T> type with zero problem which was an upgrade from our previous methodology of doing the exact same thing with Arraylists. However now using SortedList it doesnt work becuase it doesnt have an index but rather a "key" which in our case is...
14
25273
by: DaTurk | last post by:
I am makeing a Multicast server client setup and was wondering what the difference is between Socket.Connect, and Socket.Bind. It may be a stupid question, but I was just curious. Because I tried a test, and I can't bind two sockets to the same port/ip but I can connect with one socket, and bind with another to the same ip/port. Thanks
3
3217
by: steve | last post by:
I need to compare the value of a field in a row on an arraylist with the value of a field on a second arraylist I have this bit of code working for arrays but cant get it working for arraylists The secone argument here (1) represents the second field in the row, with arraylists I get a message saying to many arguments. Can I do this with arraylists or do I need to copy the arraylists to arrays? Thanks For q As Integer = 0 To 9 For j...
4
1688
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of Arraylists, meaning, I don't know how many I should create until runtime. I will be reading a table, and 0,1,2, or more fields have to be put into individual ArrayLists. How do I create an unknown number of ArrayLists? Right now I put all the values into one ArrayList. I know how many fields are in the ArrayList so I then know that every one, or every other one, or
2
7979
by: John A Grandy | last post by:
Is there a way to quickly bind/populate a dropdown list with an enum ?
0
9669
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
9515
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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...
1
10155
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
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
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
3718
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.