[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

set radio button item text dynamically

The following code is the create two items dynamically for a radio button.  How can I set the display text as STATE LEVEL and CITY LEVEL without the dashes?  Thanks.

            Report_level.Items.Add("STATE_LEVEL")
            Report_level.Items.Add("CITY_LEVEL")

0
ewang1205
Asked:
ewang1205
  • 3
  • 3
1 Solution
 
sachitjainCommented:
Report_level.Items.Add(new ListItem("State Level","STATE_LEVEL"));
Report_level.Items.Add(new ListItem("City Level","CITY_LEVEL"));

In ListItem constructor, two parameters passed are value and name pair.
I hope it works.

Regards
Sachit Jain
0
 
sachitjainCommented:
Let me correct myself....
In ListItem constructor, two parameters passed are text and value.

Regards
Sachit.
0
 
ewang1205Author Commented:
I like the text to be STATE LEVEL and value to be STATE_LEVEL.  How to do that?  Thanks.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ewang1205Author Commented:
I see the value and text now.  Let me try and update the results.  Thanks.

Report_level.Items.Add(new ListItem("State Level","STATE_LEVEL"));
Report_level.Items.Add(new ListItem("City Level","CITY_LEVEL"));
 
0
 
ewang1205Author Commented:
Thanks.  Works great.  Now if I need to remove the list, will the following work?  


Report_level.Items.Remove(new ListItem("State Level","STATE_LEVEL"));
Report_level.Items.Remove(new ListItem("City Level","CITY_LEVEL"));
0
 
sachitjainCommented:
No man u just need to remove it through its index like

Report_level.Items.RemoveAt(1);
Above step would delete second item from list.

If u want to delete through item then u have to follow these steps:

ListItem item1 = new ListItem("State Level","STATE_LEVEL");
ListItem item2 = new ListItem("City Level","CITY_LEVEL");

Report_level.Items.Add(item1);
Report_level.Items.Add(item2);

Report_Level.Items.Remove(item2);

Regards
Sachit.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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