How to set text in RadioButtonList from code behind?

  • Thread starter Thread starter staeri
  • Start date Start date
S

staeri

I have a RadioButtonList like this:

<asp:RadioButtonList ID="lstReportType" runat="server">
<asp:ListItem Selected="True"
Value="CompanyCheck">Text 1</asp:ListItem>
<asp:ListItem Value="CompanyStandard">Text 2</
asp:ListItem>
<asp:ListItem Value="CompanyExtended">Text 3</
asp:ListItem>
</asp:RadioButtonList>

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

Very grateful for reponse!

// S
 
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(object sender, EventArgs e) {
this.lstReportType.Items[0].Text = "Blah";
}
 
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(object sender, EventArgs e) {
    this.lstReportType.Items[0].Text = "Blah";

}



I have a RadioButtonList like this:
<asp:RadioButtonList ID="lstReportType" runat="server">
               <asp:ListItem Selected="True"
Value="CompanyCheck">Text 1</asp:ListItem>
               <asp:ListItem Value="CompanyStandard">Text 2</
asp:ListItem>
               <asp:ListItem Value="CompanyExtended">Text 3</
asp:ListItem>
</asp:RadioButtonList>
I need to change the text of the ListItems from the code behind file.
How can that be done?
Very grateful for reponse!
// S- Dölj citerad text -

- Visa citerad text -

Thanks a lot! I'll try this.

// S
 
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 thatare
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(object sender, EventArgs e) {
    this.lstReportType.Items[0].Text = "Blah";
- Visa citerad text -

Thanks a lot! I'll try this.

// S- Dölj citerad text -

- Visa citerad text -

I've tried your solution but nothing happens with the text. I'm using
vb and I've tried in Page_Load:

Me.lstReportType.Items(0).Text = "Blah"
lstReportType.Items(0).Text = "Blah"

What can be wrong?

// S
 
Back
Top