Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide one of the radiobutton in radiobutton list?

Let say I want to hide one of the radio buttons with value 0, what code can make it visible = false? I was using Javascript, C# and ASP.NET.

<asp:ListItem Value="1"> 1&nbsp</asp:ListItem>
<asp:ListItem Value="2"> 2&nbsp</asp:ListItem>
<asp:ListItem Value="3"> 3&nbsp</asp:ListItem>
<asp:ListItem Value="4"> 4</asp:ListItem>
<asp:ListItem Value="0" Selected="True" Enabled="False">

foreach (ListViewDataItem item in ListView1.Items)
{
    var rbl = (RadioButtonList)item.FindControl("rblSelect");
    var selectedValue = int.Parse(rbl.SelectedItem.Value);
    var selectedText = rbl.SelectedItem.Text;
    var selectedIndex = rbl.SelectedIndex;
    rbl.Items[0].Attributes.CssStyle.Add("visibility", "hidden");
}
like image 948
user3115280 Avatar asked Mar 16 '14 08:03

user3115280


People also ask

How hide Radiobuttonlist item in asp net?

Changes ("display", "none") to ("visibility", "hidden") to hide it.

How do you make a list visible false in asp net?

If it's sufficient to disable an item you can simply use approveItem. Enabled = false .

What is the difference between radio button and radio button list?

An asp:radiobuttonlist creates a group of radiobuttons that ensures when one is selected, the others are deselected whereas asp:radiobutton is not within a group and therefore cannot be deselected by clicking other radio buttons.

Which property is for to set a grouping to RadioButton?

Use the GroupName property to specify a grouping of radio buttons to create a mutually exclusive set of controls. You can use the GroupName property when only one selection is possible from a list of available options. When this property is set, only one RadioButton in the specified group can be selected at a time.


2 Answers

Try This : From CodeBehind

MyRadioButtonList.Items[0].Attributes.CssStyle.Add("visibility", "hidden");

EDIT:

int count = 0; //index of item tobe hidden
foreach (ListViewDataItem item in ListView1.Items)
{


    var rbl = (RadioButtonList)item.FindControl("rblSelect");
    var selectedValue = int.Parse(rbl.SelectedItem.Value);
    var selectedText = rbl.SelectedItem.Text;
    var selectedIndex = rbl.SelectedIndex;

    if(count == 0)
       rbl.Attributes.CssStyle.Add("visibility", "hidden");

    count++;
}
like image 165
Sudhakar Tillapudi Avatar answered Sep 22 '22 22:09

Sudhakar Tillapudi


try this

rbl.Items[0].Enabled = false;
like image 40
santosh singh Avatar answered Sep 20 '22 22:09

santosh singh