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 </asp:ListItem>
<asp:ListItem Value="2"> 2 </asp:ListItem>
<asp:ListItem Value="3"> 3 </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");
}
Changes ("display", "none") to ("visibility", "hidden") to hide it.
If it's sufficient to disable an item you can simply use approveItem. Enabled = false .
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.
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.
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++;
}
try this
rbl.Items[0].Enabled = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With