By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,212 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,212 IT Pros & Developers. It's quick & easy.

Dynamically Creating RadioButtonList

P: n/a
Hello there,

I am new to ASP .NET and am tryimg to create a RadioButtonList dynamically.
My code below gives an "Index was out of range" error.

Where am I going wrong?

Sub CreateRadioButtons(ByVal dr)

' Instantiate RadioButtonList

Dim DynamicRadioButtonList As New RadioButtonList

Dim t As Integer

t = 0

Do While dr.Read()

DynamicRadioButtonList.Items(t).Text = dr("PRO_en")

t = t + 1

Loop

'Add radio button

PlaceHolderGroup.Controls.Add(DynamicRadioButtonLi st)

End Sub

Thank you for your help
Oct 11 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I have managed to solve my problem but that lead to asecond problem.

My new code is as follows:

Sub CreateRadioButtons(ByVal dr)

' Instantiate RadioButtonList

Dim RadioButtonListProfiles As New RadioButtonList

'Add radiobuttonlist into a placeholder

PlaceHolderProfiles.Controls.Add(RadioButtonListPr ofiles)
Do While dr.Read()

RadioButtonListProfiles.Items.Add(New ListItem(dr("PRO_en")))

Loop

End Sub

However I would now like to change the code on the HTML page so it can
access the radiobuttonlist via the control. Before, the code on the HTML
page was as foolows:

Sub chkLayout_CheckedChanged(sender As Object, e As EventArgs)

If chkLayout.Checked = True Then RadioButtonListProfiles.RepeatLayout =
RepeatLayout.Table

Else RadioButtonListProfiles.RepeatLayout = RepeatLayout.Flow

End If

End Sub

and it worked very well. How do I now reference the propetries of the
RadioButtonList through the PlaceHolderProfiles?

Thank you

"Tapi" <t.******@free.fr> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello there,

I am new to ASP .NET and am tryimg to create a RadioButtonList dynamically. My code below gives an "Index was out of range" error.

Where am I going wrong?

Sub CreateRadioButtons(ByVal dr)

' Instantiate RadioButtonList

Dim DynamicRadioButtonList As New RadioButtonList

Dim t As Integer

t = 0

Do While dr.Read()

DynamicRadioButtonList.Items(t).Text = dr("PRO_en")

t = t + 1

Loop

'Add radio button

PlaceHolderGroup.Controls.Add(DynamicRadioButtonLi st)

End Sub

Thank you for your help

Oct 11 '05 #2

P: n/a
Tapi wrote:
Hello there,

I am new to ASP .NET and am tryimg to create a RadioButtonList
dynamically. My code below gives an "Index was out of range" error.


There was no way for you to know it, but this is a classic asp newsgroup.
While you may be lucky enough to find a dotnet-knowledgeable person here who
can answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-knowledgeable people hang out. I
suggest microsoft.public.dotnet.framework.aspnet.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 11 '05 #3

P: n/a
Tapi wrote:
I have managed to solve my problem but that lead to asecond problem.

My new code is as follows:

Sub CreateRadioButtons(ByVal dr)
Why aren't you explicitly declaring the datatype of dr? I assume dr isn't
simply an Object, is it? I assume it's a datareader so you should declare it
as such. You should turn on Option Strict to prevent you from making this
mistake.
<snip>

However I would now like to change the code on the HTML page so it can
access the radiobuttonlist via the control. Before, the code on the
HTML page was as foolows:

Sub chkLayout_CheckedChanged(sender As Object, e As EventArgs)

If chkLayout.Checked = True Then RadioButtonListProfiles.RepeatLayout
= RepeatLayout.Table

Else RadioButtonListProfiles.RepeatLayout = RepeatLayout.Flow

End If

End Sub
This isn't html code ...? This is server-side VB.Net code.


and it worked very well. How do I now reference the propetries of the
RadioButtonList through the PlaceHolderProfiles?

I had never heard of the Placeholder class so I looked it up in online help.
Everything seems to be there. You should probably go read it and, if it
doesn't answer your question, try the aspnet group.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.