473,498 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically Creating RadioButtonList

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
3 9196
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1888
by: Joel Reinford | last post by:
I am working on an ASP.NET web app. One of the pages will be using several user controls. The controls will be loaded dynamically based on SQL Server data. I need to be able to retrieve the...
1
1642
by: Shamin | last post by:
Hi All, I'm refering to the code in this article. http://www.dnzone.com/ShowDetail.asp?NewsId=151 I'm trying to do the same in VB.NET and I'm having problems with procedure...
4
3086
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
0
2520
by: Boris | last post by:
When I dynamically create CheckButtonList, I add ListItem(s) to my CheckButtonList object chkList chkList.Items.Add(new ListItem("My Text", "My Value")); The resulting HTML doesn't contain...
5
3493
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator;...
1
1850
by: loga123 | last post by:
I have an aspx page where I am creating "radiobuttonlists" dynamically based on the result from a SQL query. "ID" property of these controls is set dynamically. Then...i have a "submit" button on...
0
2384
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
0
2673
by: swapnil1987 | last post by:
hello friends i am trying to find solution for this problem if u know something then please tell i am creating web application that runs on black berry. here i need to create selection list...
2
1911
by: premprakashbhati | last post by:
happy new year all of u... sir, iam using dataservice function of type int named getunbookedslots(DateTime dt) and the same is used for adding the returned datetime value to RadioButtonList of...
0
7197
jinu1996
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...
1
6881
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...
0
5456
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,...
1
4899
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...
0
4584
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...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
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 ...
0
287
bsmnconsultancy
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...

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.