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
264 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now