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

时间:2012-07-13 07:58:05

标签: c# javascript jquery asp.net

我希望禁用一个listItem 来自 RadioButtonList 取决于条件,如果querystring contain 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>

3 个答案:

答案 0 :(得分: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;
                    }
                }
            }

答案 1 :(得分: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"));
    }
 }

答案 2 :(得分:-1)

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

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

相关问题