是否可以从asp.net中的radioButton列表中禁用一个listItem

Sat*_*ngh 4 javascript c# asp.net jquery

我想从RadioButtonList 禁用一个listItem取决于条件,如果它然后它将显示ListItem或否则它禁用第二个listItem即(外部).因此用户无法访问第二个列表项querystring contain true

我有网址喜欢

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>
Run Code Online (Sandbox Code Playgroud)

ewi*_*ows 7

我不想从列表中删除该项目,我想像原始海报一样禁用它.因此,这里是我能够使用的代码(编辑 - 转换为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;
                    }
                }
            }
Run Code Online (Sandbox Code Playgroud)


Sat*_*ngh 3

这是我在 HariHaran 的帮助下解决的方法

 protected void Page_Load(object sender, EventArgs e)
 {
   string planType=Request.QueryString["type"];
   if (planType == "False")
    {
      rdodomiantype.Items.Remove(rdodomiantype.Items.FindByValue("1"));
    }
 }
Run Code Online (Sandbox Code Playgroud)