Mac
Mac

Reputation: 2705

ASP.Net RadioButton visibility inside a RadioButtonList

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

Upvotes: 8

Views: 17145

Answers (8)

Sumate Mephokkij
Sumate Mephokkij

Reputation: 13

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.

Upvotes: 0

James Hall
James Hall

Reputation: 6689

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");

}

Upvotes: 0

Airn5475
Airn5475

Reputation: 2492

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")

Upvotes: 3

Dillie-O
Dillie-O

Reputation: 29745

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.

Upvotes: 6

BlueGreenWorld
BlueGreenWorld

Reputation: 1

Try This:

RadioButtonList.Items.Remove(RadioButtonList.Items.FindByValue("3"));

Upvotes: 1

Aaron
Aaron

Reputation:

Why not add and remove the radio buttons as needed?

RadioButtonList.Items.Add("Item Name" or index);
RadioButtonList.Items.Remove("Item Name" or index);

Upvotes: 2

RedWolves
RedWolves

Reputation: 10395

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

Upvotes: 0

Zack Peterson
Zack Peterson

Reputation: 57373

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.

Upvotes: 0

Related Questions