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

Is it possible to disable one listItem from radioButton list in asp.net

本文关键字:listItem 一个 列表 radioButton net asp 是否      更新时间:2023-09-26

我想RadioButtonList禁用一个listItem,这取决于条件,比如如果querystring contain true,它将同时显示listItem,否则它将禁用第二个listItemie(外部)。因此用户无法访问第二个列表项

我有类似的url

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>

我不想从列表中删除该项目,我想像原始海报要求的那样禁用它。因此,以下是我能够使用的代码(EDIT-转换为C#,并根据原始帖子检查querystring参数:

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

以下是我如何在HariHaran 的帮助下解决的问题

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

是否需要禁用一个列表项?我的建议是根据查询字符串值可以绑定下拉列表。即如果查询字符串值为true,则可以将下拉列表与两个列表项值绑定;

或者,如果查询字符串值为false,则可以仅将下拉列表与第一个列表项绑定。