我想从 RadioButtonList 中禁用一个 listItem 取决于条件,例如如果 querystring 包含 true
那么它将同时显示 ListItem 否则它禁用第二个 listItem 即(外部)。所以用户不能访问第二个列表项
我有这样的网址
abc.com/Account.aspx?type=true
abc.com/Account.aspx?type=false
Account.aspx 页面代码
<asp:RadioButtonList ID="rdodomiantype" runat="server" RepeatDirection="Horizontal" onclick="setTextbox()">
<asp:ListItem Selected="True" Value="0" >Default</asp:ListItem>
<asp:ListItem Value="1" >External</asp:ListItem>
</asp:RadioButtonList>
最佳答案
我不想从列表中删除该项目,我想像原始发布者所要求的那样禁用它。因此,这是我能够使用的代码(编辑 - 转换为 C# 并根据原始帖子检查查询字符串参数:
if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"].ToUpper() == "TRUE")
{
foreach (ListItem item in rdoList.Items)
{
if (item.Text == "External")
{
item.Enabled = false;
item.Attributes.Add("style", "color:#999;");
break;
}
}
}
关于c# - 是否可以从 asp.net 中的 radioButton 列表中禁用一个 listItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11466393/