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. 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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
...
|
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", " ", " "}
}
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
| |
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...
|
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...
|
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: 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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |