Is it possible to disable one listItem from radioButton list in asp.net
Solution 1
Here how i solved with the help of HariHaran
protected void Page_Load(object sender, EventArgs e)
{
string planType=Request.QueryString["type"];
if (planType == "False")
{
rdodomiantype.Items.Remove(rdodomiantype.Items.FindByValue("1"));
}
}
Solution 2
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;
}
}
}
Satinder singh
I am a Full Stack Developer have a passion to create, solve, and deploy software applications. I have a great passion to learn new things. ForEach(minute in MyLife) { myExperience ++; } Blog: Codepedia Video: Subscribe Youtube Channel
Updated on June 14, 2022Comments
-
Satinder singh almost 2 years
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 itemI 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>