How to set text in RadioButtonList from code behind?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • staeri@gmail.com

    How to set text in RadioButtonList from code behind?

    I have a RadioButtonList like this:

    <asp:RadioButto nList ID="lstReportTy pe" runat="server">
    <asp:ListItem Selected="True"
    Value="CompanyC heck">Text 1</asp:ListItem>
    <asp:ListItem Value="CompanyS tandard">Text 2</
    asp:ListItem>
    <asp:ListItem Value="CompanyE xtended">Text 3</
    asp:ListItem>
    </asp:RadioButton List>

    I need to change the text of the ListItems from the code behind file.
    How can that be done?

    Very grateful for reponse!

    // S
  • Jeff Winn

    #2
    Re: How to set text in RadioButtonList from code behind?

    Depends on where you need them changed at, in the example I'm just changing
    the text on the page's load event.

    The Items property on the control contains the collection of items that are
    being displayed to the user. If you must want to modify the text of an item,
    grab it from the collection by the index you're wanting to change (keeping
    in mind that it's a zero-based index) and set the text property.

    protected void Page_Load(objec t sender, EventArgs e) {
    this.lstReportT ype.Items[0].Text = "Blah";
    }

    <staeri@gmail.c omwrote in message
    news:67a7d92d-da75-49fd-85ca-85e2dfcab5c5@j2 2g2000hsf.googl egroups.com...
    >I have a RadioButtonList like this:
    >
    <asp:RadioButto nList ID="lstReportTy pe" runat="server">
    <asp:ListItem Selected="True"
    Value="CompanyC heck">Text 1</asp:ListItem>
    <asp:ListItem Value="CompanyS tandard">Text 2</
    asp:ListItem>
    <asp:ListItem Value="CompanyE xtended">Text 3</
    asp:ListItem>
    </asp:RadioButton List>
    >
    I need to change the text of the ListItems from the code behind file.
    How can that be done?
    >
    Very grateful for reponse!
    >
    // S

    Comment

    Working...