简体   繁体   English

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

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

I want to disable one listItem from RadioButtonList depend on condition like if querystring contain true then it will display both the ListItem or else it disabled 2nd listItem ie(External). 我想从RadioButtonList中 禁用一个listItem取决于条件,如果querystring contain true那么它将同时显示ListItem或者禁用第二个listItem即(外部)。 So user can't access 2nd list item 因此用户无法访问第二个列表项

I have url like 我有网址喜欢

abc.com/Account.aspx?type=true

abc.com/Account.aspx?type=false

Code On page Account.aspx 代码页面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>

I didn't want to remove the item from a list, I wanted to disable it like the original poster asked. 我不想从列表中删除该项目,我想像原始海报一样禁用它。 As such, here's the code I was able to use (EDIT - converted to C# and checking for querystring param based on original post: 因此,这里是我能够使用的代码(编辑 - 转换为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;
                    }
                }
            }

Here how i solved with the help of HariHaran 在这里我是如何在HariHaran的帮助下解决的

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

Is it necessary to disable one list item? 是否需要禁用一个列表项? My suggestion is according to the query string value you can bind the dropdown. 我的建议是根据查询字符串值你可以绑定下拉列表。 ie if the query string value is true then you van bind the dropdown with both list item values; 即如果查询字符串值为true,那么您将下拉列表与两个列表项值绑定;

or if the query string value is false you can bind the dropdown with first list item only. 或者,如果查询字符串值为false,则只能将下拉列表与第一个列表项绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM