Solved

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

Posted on 2008-10-25
7
267 Views
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 asp.net 2.0 VB?
Thanks so much.
0
Comment
Question by:bolenka
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:AmarIs26
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.
0
 

Author Comment

by:bolenka
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 problem...so thank you. I did not know that it rendered 2 elements separately. Can you tell how it renders by Viewing Source?

0
 
LVL 6

Expert Comment

by:AmarIs26
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.
http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en
 
 
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 6

Expert Comment

by:AmarIs26
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;
RadioList.Databind();
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.
0
 

Author Comment

by:bolenka
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
Next

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.
0
 
LVL 6

Accepted Solution

by:
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
ListItem.attributes.add("class","wronganswer")
ListItem.Attributes.add("class","rightanswer")

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.
 
 
0
 

Author Closing Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

803 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