ASP.Net RadioButton visibility inside a RadioButtonList
Asked Answered
P

8

8

Is there a way to hide radio buttons inside a RadioButtonList control programmatically?

Phelgon answered 28/8, 2008 at 20:37 Comment(0)
M
6

Under the hood, you can access the attributes of the item and assign it a CSS style.

So you should be able to then programmatically assign it by specifying:

RadioButtonList.Items(1).CssClass.Add("visibility", "hidden")

and get the job done.

Mho answered 28/8, 2008 at 20:52 Comment(4)
'CssStyle' is not a member of 'System.Web.UI.WebControls.ListItem'. I understand setting visibility, but not sure where the CssStyle property is coming from...Rippy
Ahh, an old typo, it should have been the CssClass property and not CssStyle. I've updated things accordingly.Mho
'CssClass' is not a member of 'System.Web.UI.WebControls.ListItem'. Sorry :PRippy
Correct, but it is part of it's parent WebControl class and should be inherited down. (See: msdn.microsoft.com/en-us/library/…) You might need to check your references if you're not seeing it in your intellisense.Mho
R
3

Here's how you have to apply a style attribute to a listitem:

RadioButtonList.Items(1).Attributes.Add("style", "display:none")
- OR -
RadioButtonList.Items(1).Attributes.Add("style", "visibility:hidden")

Rippy answered 29/8, 2012 at 12:32 Comment(0)
J
2

Why not add and remove the radio buttons as needed?

RadioButtonList.Items.Add("Item Name" or index);
RadioButtonList.Items.Remove("Item Name" or index);
Jory answered 25/11, 2008 at 22:26 Comment(0)
H
1

Try This:

RadioButtonList.Items.Remove(RadioButtonList.Items.FindByValue("3"));
Hullabaloo answered 28/8, 2008 at 20:37 Comment(0)
S
0

If you mean with JavaScript, and if I remember correctly, you've got to dig out the ClientID properties of each <input type="radio" ...> tag.

Swept answered 28/8, 2008 at 20:46 Comment(0)
M
0

Have you tried to hide it through the itemdatabound event onload or do you need it to hide after it loads?

Meshed answered 28/8, 2008 at 20:48 Comment(0)
M
0

I haven't tested it, but I'd assume (for C#)

foreach(ListItem myItem in rbl.Items)
{
if(whatever condition)
myItem.Attributes.Add("visibility","hidden");

}
Mongeau answered 28/8, 2008 at 20:54 Comment(2)
Sorry @James, visibility is a style not an attribute.Rippy
Yeah agreed. That was way back in the day before i knew CSS really well.Mongeau
F
0

Another answer to not visibility inside a RadioButtonList.

Try this code:

RadioButtonList.Items(1).CssClass.Add("display", "none");

and get the job to no display RadioButtonList in layout.

Folie answered 27/12, 2019 at 7:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.