How do I set the height and display attributes for a dynamic radiobuttonList on a form in vb?

Posted on 2008-10-25
Last Modified: 2013-12-26
I am adding list items to a radiobuttonlist from a database dynamically in ASP.Net VB. When I view the form, the radiobuttonlist is all sprawled out over the page. There is sooooo much space between the listitems I have dynamically added.

How do I format a dynamically added RadiobuttonList in 2.0 VB?
Thanks so much.
Question by:bolenka
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 22806996
The radiobutton list renders two elements. Label and Input. Make sure that your css files or css styles are not setting the styles of these two elements which might cause them to look too far apart etc.
Also by default the "RepeatDirection" property of the RadioButtonList is set to Verticle. If thats what you want ensure that, this value is set because otherwise your radio buttons will be all rendered on the same line.
Finally, ensure that the RepeatLayout property of the radiobuttonlist is set to Table.
It would help if you could post some screenshots and css styles that are currently applied to the page elements.

Author Comment

ID: 22807067
ok, I didnt know that it rendered two elements. Is it possible to take the label text that the radiobutton is outputting and output the results on postback (without the actual button part)? Meaning if I have a radiobutton and the user selects an answer and clicks submit then can I just show the results from the label of the radiobuttonlist without the actual buttons. I don't want the user to be able to click the button again after postback.

I think I acually my CSS was causing the thank you. I did not know that it rendered 2 elements separately. Can you tell how it renders by Viewing Source?


Expert Comment

ID: 22808028
yes you can, i would suggest you download whats called "Developers toolbar" its an addin to IE by microsoft which lets you click on any element and see its structure. You can also dynamically apply css styles and see what effect it would have on elements. So when something apears out of place you can try to fix it by applying styles.
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.


Expert Comment

ID: 22808043
Also to answer your first question,. what you can do is that when your radiobuttonlist is being built (either by adding Listitem in a loop or by databinding)
you can get a reference to the listitem , identify that it is currently ticked and then disable it so the user cannot select it again.
IF you are doing something like
RadioList.DataSource = dbresult;
then you need to handle the itemcreated or radiolist.itemdatabound event (i am typing this without vs so the event names might not be exact so just look for something similar). in one of these events you can get a reference to the ListItem that is being added to the list during databind and then you can do the check to enable/disable the item.
If you are adding items to your radiobuttonlist in a loop then it should be easy to add the necessary code in the loop.

Author Comment

ID: 22809560
I am actually adding items to my radiobuttonlist in a loopin the PageLoad event. Is this the correct event to add them? Then I just disable them on postback?

One last question since you have been so helpful, what would be the best way to display info abou t the button that was clicked? Would I just disable it on postback and set the drawing color on postback?

(Red for incorrect, green for correct) and then I have to display a label to display statistics data...can I append information to the list item on postback to post information about the chosen answer? (i.e"88% of users have chosen this answer..12% of users have chosen this answer")...or would it be better to use a label

If I load the data on page load into a datarow loop:
For Each row As Data.DataRow In matchRows

then howdo I append information about the answer on postback?

P.S. I wish I could give you 1000 points you have been so helpful:) I have downloaded the tool you suggested and will take a look at it shortly...thanks for that as well.

Accepted Solution

AmarIs26 earned 500 total points
ID: 22810688
Hi, I assume you are only adding the items once?
If not Page.IsPostBack Then
'Add ListItems
End If
That way when the user selects an answer and submits (postback happens) you can then loop through the radiobuttonlist and check which item is checked. Whichever radiobutton is checked and if that is the correct answer what you can do is you can add attribute to the listitem

This will highlight the item background (you need to create the appropriate css classes).
can I append information to the list item on postback to post information about the chosen answer?
To display the stats you should use a label somewhere on the page (underneath the radiobutton list) to show the stats. But you can also reset the radiobutton text so it shows  "Answer1  (Incorrect)"
"Answer 2 (Correct)".
Do not show too much information on the radiobutton text. Just append the incorrect or correct.

Author Closing Comment

ID: 31509967
awesome, I have a related question, but I wanted to give you point first. thanks sooo much.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question