I'm trying to set the text of the different radio buttons in a radio button list based of values from a database. I'm getting an error with the following code:
the radio list looks like this (btw its in a custom control):
<asp:radiobuttonlist id="radio1" runat="server"
<asp:listitem id="optionA" runat="server"></asp:listitem>
<asp:listitem id="optionB" runat="server"></asp:listitem
</asp:radiobuttonlist
here's the error causing line:
ListItem optionA = (ListItem)this.FindControl("optionA");
and here's the error:
"Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ListItem"
Hmmm... Any ideas?The way to approach this would be to first use FindControl to find the radio button list control. The list item can then be found by using the RadioButtonLists Item index.
RadioButtonList RadioButtonList1 (RadioButtonList1)this.FindControl("RadioButtonList1")
ListItem optionA = RadioButtonList1.Item(0)
Hope this helps.
Glen.
0 comments:
Post a Comment