假设我要隐藏值为0的单选按钮之一,哪些代码可使它可见= false?我正在使用Javascript,C#和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");
}
最佳答案
试试看:从CodeBehind
MyRadioButtonList.Items[0].Attributes.CssStyle.Add("visibility", "hidden");
编辑:
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++;
}