473,657 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databind multidimensiona l 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.DataSo urce = months
expmonth.DataTe xtField = ??
expmonth.DataVa lueField = ??
expmonth.DataBi nd()

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 4642
Hi,

You can not bind to a multidimensiona l array. Try creating a class
to hold the info instead.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.D ataSource = months

DropDownList1.D ataTextField = "Name"

DropDownList1.D ataValueField = "Id"

DropDownList1.D ataBind()

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**********@g mail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.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.DataSo urce = months
expmonth.DataTe xtField = ??
expmonth.DataVa lueField = ??
expmonth.DataBi nd()

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
2136
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 manager doesn't seem to spike and CPU usage only gets as high as 11 to 13 percent. A sample script is provided below, any help or alternative solutions are welcome. (By the way, the script below works fine on Linux with the same version of Apache...
1
1410
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 helpful. Here is the code: #include <iostream> #include <conio> using namespace std; class Mat
8
13943
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 the array can vary depending on the parameters passed. What I need to do is loop through the returned array and if applicable write the array element to the screen.
11
17637
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 s(i)=new string(test) Above line gives - error implicit conversion string to 1-dim array of
1
1885
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
28354
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 each element but I am having issues using redim to adjust the new array. Any help or example code would be greatly appreciated. thanks!
5
5378
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 something like this? var $userArray = array(array());
6
2252
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 reading the data from the file. I've tried reading the file to obtain the bounds of each dimension, but I can't seem to get ReDim to work. All I want to do is get this data into a global 2-D array, so that all functions in my class have access to...
5
4316
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 now with the code posted below. I get this type of output. Resource : 0 Resource : 1 Resource : 2
0
8385
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
8303
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
8821
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
8602
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
7316
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...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1941
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.