Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). 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

  <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>
like image 540
Satinder singh Avatar asked Jul 13 '12 07:07

Satinder singh


1 Answers

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:

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;
                    }
                }
            }
like image 160
ewitkows Avatar answered Oct 25 '22 01:10

ewitkows