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>
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;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With