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/Account.aspx?type=true
abc/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 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./Account.aspx?type=true
abc./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>
Share
Improve this question
edited Jul 13, 2012 at 9:35
Satinder singh
asked Jul 13, 2012 at 7:58
Satinder singhSatinder singh
10.2k18 gold badges64 silver badges102 bronze badges
2
- I think the reason you have been downvoted is that you start your "question" with My requirement is ... this is a Q and A site - not a rent a developer site ... please rephrase it so that it reads like a question and shows effort on your part to resolve your issue – Manse Commented Jul 13, 2012 at 9:10
- @ManseUK: Thank you and i apologies for that – Satinder singh Commented Jul 13, 2012 at 9:28
3 Answers
Reset to default 7I 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;
}
}
}
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"));
}
}
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;
or if the query string value is false you can bind the dropdown with first list item only.