473,398 Members | 2,113 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,398 software developers and data experts.

How to store list

Hi,

I would appreciate knowing the best way to store a two dimensional array,
and the bind that array to a dropdownlist.

The original array is in the form

integer, string

and the list will look like this

1,"sdfsdf"
2,"dsfsdf"
3,"gfhfghgfhfg"

The integer will eventually bind to the datavalue field of the dropdown.
The string will eventually bind to the dataText field of the dropdown.

I know I could bing directly to a dataset although I have three instance of
the same dropdown on the page.
so I figured fill an array once from a database and the populating the three
dropdowns from an array, is better then going to the db 3 times for the same
information.

can anybody please point me in the correct direction.

cheers

martin.


Nov 18 '05 #1
2 1429
Hey Martin,

I wonder if a Hashtable is what you want here? It seems pretty easy to jam
the data into it using the Add method and then assign the Hashtable to the
ddl. Here's some code:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim hsh As New Hashtable
hsh.Add(1, "sdfsdf")
hsh.Add(2, "dsfsdf")
hsh.Add(3, "gfhfghgfhfg")
DropDownList1.DataSource = hsh
DropDownList1.DataTextField = "Value"
DropDownList1.DataValueField = "Key"
DropDownList1.DataBind()
' More on this here:
'
http://it.maconstate.edu/tutorials/A...pnet07-02.aspx
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]
"martin" <St**************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I would appreciate knowing the best way to store a two dimensional array,
and the bind that array to a dropdownlist.

The original array is in the form

integer, string

and the list will look like this

1,"sdfsdf"
2,"dsfsdf"
3,"gfhfghgfhfg"

The integer will eventually bind to the datavalue field of the dropdown.
The string will eventually bind to the dataText field of the dropdown.

I know I could bing directly to a dataset although I have three instance
of
the same dropdown on the page.
so I figured fill an array once from a database and the populating the
three
dropdowns from an array, is better then going to the db 3 times for the
same
information.

can anybody please point me in the correct direction.

cheers

martin.


Nov 18 '05 #2
Hi ken,

your hashtable idea is good,

however since my last post I have created an arraylist like this

Public Class Region
Private m_ID As Integer
Private m_Text as String

Public Sub New(ByVal intID As Integer, ByVal strText As String)
m_ID = intID
m_Text = strText
End Sub

End Class

Public Function GetRegionList() As ArrayList
Dim ds As New DataSet
Dim Regions As Region
Dim arrList As New ArrayList
Try
ds = SqlHelper.ExecuteDataset(strConn(),
CommandType.StoredProcedure, "spRegionsGetAll")
Catch ex As Exception
System.Web.HttpContext.Current.Trace.Write("**ERRO R***",
ex.Message.ToString)
Throw (ex)
End Try
If Not ds Is Nothing Then
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count
arrList.Add(New Region(ds.Tables(0).Rows(0).Item(0),
ds.Tables(0).Rows(0).Item(0)))
Next
End If
Return arrList
End Function

what I would like to do is loop through the arraylist and access each of the
elements like so

Public Shared Function Bind(ByRef cmb As
System.Web.UI.WebControls.DropDownList, ByVal arrList As ArrayList)
Dim i As Integer
For i = 0 To arrList.Count
'cmb.Items.Insert(0, New
System.Web.UI.WebControls.ListItem("Please Select", "0"))
cmb.Items.Insert(0, New
System.Web.UI.WebControls.ListItem(arrList??????, arrList??????))
Next
End Function

I think your solution is better bu would luv to know how to get the result
above.

cheers

martin






"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:uR**************@TK2MSFTNGP12.phx.gbl...
Hey Martin,

I wonder if a Hashtable is what you want here? It seems pretty easy to jam the data into it using the Add method and then assign the Hashtable to the
ddl. Here's some code:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim hsh As New Hashtable
hsh.Add(1, "sdfsdf")
hsh.Add(2, "dsfsdf")
hsh.Add(3, "gfhfghgfhfg")
DropDownList1.DataSource = hsh
DropDownList1.DataTextField = "Value"
DropDownList1.DataValueField = "Key"
DropDownList1.DataBind()
' More on this here:
'
http://it.maconstate.edu/tutorials/A...pnet07-02.aspx
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]
"martin" <St**************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I would appreciate knowing the best way to store a two dimensional array, and the bind that array to a dropdownlist.

The original array is in the form

integer, string

and the list will look like this

1,"sdfsdf"
2,"dsfsdf"
3,"gfhfghgfhfg"

The integer will eventually bind to the datavalue field of the dropdown.
The string will eventually bind to the dataText field of the dropdown.

I know I could bing directly to a dataset although I have three instance
of
the same dropdown on the page.
so I figured fill an array once from a database and the populating the
three
dropdowns from an array, is better then going to the db 3 times for the
same
information.

can anybody please point me in the correct direction.

cheers

martin.

Nov 18 '05 #3

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

Similar topics

10
by: Craig Lister | last post by:
I'm a newbie.. I'm trying to list all files in a directory, and store them in a aFile object. As I iterate through each file, I store the size, name, path, date etc... How do I store them...
10
by: Paul Cheetham | last post by:
Hi, I am developing an application that needs to store some machine-specific settings. The application is going to be published on the network in order to keep the clients on the latest version....
0
by: sajenia | last post by:
i need to design a solid data store device. the prime use of the data store is to store text messages, with each message being structured as a linked list. the logical concept of the store will be a...
9
by: Ajinkya | last post by:
Hello friends ! , I am very new to java script.If anyone can help me then I will be very very thankful to his/her. I am using php and mysql in my project and I have one textarea and one...
0
by: Brian Vanderburg II | last post by:
Lance Gamet wrote: Lance Gamet wrote: One way I've just started to use it to create a utility function to return the location of the user data folder, depending on the operating system: import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.