radiobuttonlist: omit label when .DataBind()

H

hellrazor

Hi there,

I'm successfully streaming a list of items into a radiobuttonlist. I am
using an ArrayList as a data source, which I have built from a table of
values in a MySQL table. It's working great. My only issue is that it is
printing the label along the rendering of the radio objects. How do I
keep the radiobuttonlist object from displaying the labels?

So for example, I've got the following ArrayList:

arrayList1 = New ArrayList
arrayList1.Add("one")
arrayList1.Add("two")
arrayList1.Add("three")


radiobuttonlist1.DataSource = arrayList1
radiobuttonlist1.DataBind

In the HTML page, the following is displayed:

o One
o Two
o Three

I want to just display:

o
o
o

And maybe have the label text actually be the value of each radio object.

Any suggestions?

Thanks in advance.
 
A

Andy Gaskell

Here's what I ended up doing to make the text empty:

1. Create a class to hold the string

Public Class RadioListItem

Private s As String

Public Property MyString() As String
Get
MyString = s
End Get
Set(ByVal Value As String)
s = Value
End Set
End Property

Public ReadOnly Property EmptyString() As String
Get
EmptyString = String.Empty
End Get
End Property

End Class

2. Change the code in the page slightly
Dim item1 As New RadioListItem
item1.MyString = "One"

Dim item2 As New RadioListItem
item2.MyString = "Two"

Dim item3 As New RadioListItem
item3.MyString = "Three"


Dim al As New ArrayList
al.Add(item1)
al.Add(item2)
al.Add(item3)

RadioButtonList1.DataSource = al
RadioButtonList1.DataTextField = "EmptyString"
RadioButtonList1.DataBind()

I'm a little unclear on what "And maybe have the label text actually be the
value of each radio object." means. If you can give an example of what
you're looking for I'll try to help you out.
 
H

hellrazor

Here's what I ended up doing to make the text empty:

1. Create a class to hold the string

Public Class RadioListItem

Private s As String

Public Property MyString() As String
Get
MyString = s
End Get
Set(ByVal Value As String)
s = Value
End Set
End Property

Public ReadOnly Property EmptyString() As String
Get
EmptyString = String.Empty
End Get
End Property

End Class

2. Change the code in the page slightly
Dim item1 As New RadioListItem
item1.MyString = "One"

Dim item2 As New RadioListItem
item2.MyString = "Two"

Dim item3 As New RadioListItem
item3.MyString = "Three"


Dim al As New ArrayList
al.Add(item1)
al.Add(item2)
al.Add(item3)

RadioButtonList1.DataSource = al
RadioButtonList1.DataTextField = "EmptyString"
RadioButtonList1.DataBind()

I'm a little unclear on what "And maybe have the label text actually
be the value of each radio object." means. If you can give an example
of what you're looking for I'll try to help you out.

Thanks for the reply,

I ended up adding each radio item manually... well, iterating through the
array:

travelModesArrayListValues = a flat array holding each value I need to
stream out as radio buttons.



If Not Page.IsPostBack Then

For i = 0 To travelModesArrayListValues.Count - 1
radioButtonListObj.Items.Add(New ListItem("", _
travelModesArrayListValues.Item(i)))
Next i

End If
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top