I've got a strange questions and more than likely a simple answer so here goes. I have created a few web forms that hook up with a t开发者_如何学运维able and save the values of the selected radiobuttonlists. In a few cases there may be a few listitems that have the same value but different text such as
<asp:RadionButtonList runat="server" id="RadioButtonList1">
<asp:ListItem Value="2">Yes</asp:ListItem>
<asp:ListItem Value="2">Of course</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</RadioButtonList>
For the rest of the radiobuttonlist's where values are all unique I just fill them out with
me.RadioButtonList1.SelectedValue = dr("ValueA")
I have tried to save the selectedindex and fill it that way with
me.RadioButtonList1.SelectedIndex = dr("ValueAIndex")
But this just will go to the top listitem of that value rather than the correct one.
Any help would be awesome! Many thanks! Dan
Since the only unique item is the Text
to search on, could you do:
RadioButtonList1.SelectedIndex =
RadioButtonList1.Items.IndexOf(
RadioButtonList1.Items.FindByText("ValueAText"));
Make sure to put in checks for FindByText
failing.
精彩评论