Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2144
  • Last Modified:

Disable radio button list item via asp.net code c#

I have the following radio list box:

<asp:RadioButtonList id="rdoPaymentPlan" runat="server" RepeatDirection="Horizontal">
      <asp:ListItem value="Fully Earned" id="lbEarned" selected="true">Fully Earned</asp:ListItem>
      <asp:ListItem value="Annual" id="lb1" >Annual</asp:ListItem>
      <asp:ListItem value="Semi Annual" id="lb2" >Semi Annual</asp:ListItem>
      <asp:ListItem value="Quarterly" id="lb3" >Quarterly</asp:ListItem>
</asp:RadioButtonList>

How can I disable/enabel a specific list item via ASP.Net 1.1 C#?  I can do it with javascript using:

lb1.disabled = false;

But how can I accomplish this via server-side?
0
russomr
Asked:
russomr
  • 3
  • 2
1 Solution
 
TornadoVCommented:
You can add disabled/enabled attributes to each ListItem

rdoPaymentPlan.Items[1].Attributes.Add("disabled","true");
0
 
TornadoVCommented:
Here is a great article in CodeProject:

http://codeproject.com/aspnet/disableListItems.asp
0
 
russomrAuthor Commented:
Cool.  That is a good article.  Thank you.

One last thing, the line:  lbEarned.checked = true;  does not work in the following code.  I've tried .selected and that doesn't work either.  Remember, this is a radio button list.

// enable payment plan if over 25,000
if(totalPremium >= 25000) {
      lb1.disabled      = false;
      lb2.disabled      = false;
      lb3.disabled      = false;
}else{
      lbEarned.checked = true;
      lb1.disabled      = true;
      lb2.disabled      = true;
      lb3.disabled      = true;
}

I will award your points regardless since you did answer my post, however if you know why the above lbEarned.checked does not work, it would be much appreciated.

Thanks.
0
 
TornadoVCommented:
You're welcome.

I need more details regarding "lbEarned.checked does not work" in order to answer.
0
 
russomrAuthor Commented:
For the above code:

lbEarned.checked = true;

is the line that doesn't work.  No error occur, but the radio button of lbEarned does not become the selected radio button.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now