Array Question

  • Thread starter Thread starter Shapper
  • Start date Start date
S

Shapper

Hello,

I am trying to fill a DropDownList with some array values:

Dim cultureList(,) As String = {{"Eng", "en-GB"}, {"Port", "pt-PT"}}
ddlculture.DataSource = cultureList
ddlculture.DataBind()

It's working but I get 4 items in my dropdownlist:
[Text] [Value]
English English
en-GB en-GB
Português Português
pt-PT pt-PT

I want to have something like:
[Text] [Value]
English en-GB
Português pt-PT

What am I doing wrong?

Thanks,
Miguel
 
create a class to hold the data instead of an array

Public Class Culture
Private _Name As String
Private _Code As String

Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property

Public Property Code() As String
Get
Return _Code
End Get
Set(ByVal Value As String)
_Code = Value
End Set
End Property

Public Sub New(ByVal Name As String, ByVal Code As String)
_Name = Name
_Code = Code
End Sub
End Class

create an array of these classes (or array list)

Dim cultureList(1) As Culture
cultureList(0) = New Culture("Eng", "en-GB")
cultureList(1) = New Culture("Port", "pt-PT")

ddlculture.DataSource = cultureList
ddlculture.DataBind()

in the aspx page

<asp:DropDownList Runat=server ID=ddlculture DataTextField="Name"
DataValueField="Code"></asp:DropDownList>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top