Friday, May 17, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  191] [ 5]  / answers: 1 / hits: 15551  / 10 Years ago, sun, march 16, 2014, 12:00:00

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

More From » c#

 Answers
64

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++;
}

[#71970] Friday, March 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaleyv

Total Points: 259
Total Questions: 99
Total Answers: 107

Location: Saint Helena
Member since Tue, Nov 3, 2020
4 Years ago
;