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

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.
bolenkaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AmarIs26Connect With a Mentor Commented:
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
 
AmarIs26Commented:
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
 
bolenkaAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
AmarIs26Commented:
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
 
AmarIs26Commented:
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
 
bolenkaAuthor Commented:
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
 
bolenkaAuthor Commented:
awesome, I have a related question, but I wanted to give you point first. thanks sooo much.
0
All Courses

From novice to tech pro — start learning today.