Is it possible to disable one listItem from the radioButton list in asp.net

I want to disconnect one listItem from a RadioButtonList depending on the state, such as if querystring contain true , then it will display both ListItem and disable the second listItem, i.e. (external) Thus, the user cannot access the 2nd list item

I have url like

abc.com/Account.aspx?type=true

abc.com/Account.aspx?type=false

Code On 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> 
+4
source share
3 answers

This is how I decided using HariHaran

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

I did not want to remove the item from the list, I wanted to disable it, as the original poster did. So here is the code that I was able to use (EDIT is converted to C # and checks the querystring parameter based on the original message:

 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; } } } 
+5
source

Does one list item need to be disabled? My suggestion matches a query string value that you can associate with a drop-down list. those. if the value of the query string is true, then you bind a drop-down list with two values โ€‹โ€‹of the list items;

or if the value of the query string is false, you can associate the drop-down list with only the first element of the list.

-1
source

All Articles