473,503 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databind multidimensional string array

Seems like this should be simple, but I'm new to vb.net. I've created
a array of strings. I want to bind them to a dropdown list. I was
able to do this with a one dimensional array with no problem, but with
a separate column for text and value, I can't find how to tell it which
columns to use. Code:

Dim months(,) As String = {{"00", "Select One"}, {"01", "January"},
{"02", "February"}, {"03", "March"}}
expmonth.DataSource = months
expmonth.DataTextField = ??
expmonth.DataValueField = ??
expmonth.DataBind()

So basically I just want to know what to put where the question marks
are. Seems like it should be obvious, but so far everything I've tried
hasn't worked. Could be I'm not creating the array to begin with, but
don't know.

Thanks in advance for any help.

Nov 21 '05 #1
1 4636
Hi,

You can not bind to a multidimensional array. Try creating a class
to hold the info instead.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

Dim months As New ArrayList

months.Add(New MyData("00", "Select One"))

months.Add(New MyData("01", "January"))

months.Add(New MyData("02", "Feburary"))

months.Add(New MyData("03", "March"))

DropDownList1.DataSource = months

DropDownList1.DataTextField = "Name"

DropDownList1.DataValueField = "Id"

DropDownList1.DataBind()

End If

End Sub

The class

Public Class MyData

Private mstrId As String

Private mstrName As String

Public Sub New(ByVal iId As String, ByVal sName As String)

mstrId = iId

mstrName = sName

End Sub

Public Property Id() As String

Get

Return mstrId

End Get

Set(ByVal Value As String)

mstrId = Value

End Set

End Property

Public Property Name() As String

Get

Return mstrName

End Get

Set(ByVal Value As String)

mstrName = Value

End Set

End Property

End Class

Ken
----------------------
"IGotNothin" <do**********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Seems like this should be simple, but I'm new to vb.net. I've created
a array of strings. I want to bind them to a dropdown list. I was
able to do this with a one dimensional array with no problem, but with
a separate column for text and value, I can't find how to tell it which
columns to use. Code:

Dim months(,) As String = {{"00", "Select One"}, {"01", "January"},
{"02", "February"}, {"03", "March"}}
expmonth.DataSource = months
expmonth.DataTextField = ??
expmonth.DataValueField = ??
expmonth.DataBind()

So basically I just want to know what to put where the question marks
are. Seems like it should be obvious, but so far everything I've tried
hasn't worked. Could be I'm not creating the array to begin with, but
don't know.

Thanks in advance for any help.
Nov 21 '05 #2

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

Similar topics

3
2129
by: jdemello | last post by:
When using a multidimensional associative array to cross-reference data in a second, single-dimensional array, PHP stops processing data after a few iterations. Memory usage according to the task...
1
1398
by: undbund | last post by:
Hi, i am learing how to create a multidimensional dynamic array.I want to initialize the array in the constructor. I have tried looking for the solution in this news group but none of them were...
8
13935
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
11
17622
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
1
1875
by: Arjen | last post by:
Hi, I want to have a multi string array, but I don't know the syntax. private string myArray = new string { {"1", "a", " ", " "}, {"2", "b", " ", " "}, {"3", "c", " ", " "} }
5
28306
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
5
5371
by: KDawg44 | last post by:
Hi, Is there a way to get a multidimensional associative array with the entire result set? I would like to get a an array like this: resultsArray How can I accomplish this? Can I do...
6
2244
srj115
by: srj115 | last post by:
I have a text file containing 2 dimensions (parents,children). There are an indeterminite number of parents, and each parent has an indeterminite of children (ie, both dynamic). I have no problems...
5
4298
by: rottmanj | last post by:
I am trying to build a multidimensional vector array that allows for multiple child elements under each parent element, but I am having a heck of a time trying to figure out how to do it. Right...
0
7188
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,...
0
7258
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,...
0
7313
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...
1
6970
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...
1
4987
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...
0
4663
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...
0
3156
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...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.