views:

33

answers:

2

Hey,

I have a RadioButtonList wich contain 4 radio buttons A,B,C,D

RBQ.Items.Add("A")
RBQ.Items.Add("B")
RBQ.Items.Add("C")
RBQ.Items.Add("D")

How can set the selected value to the radio button who has the value "B" ????

Thanks.

+1  A: 
RBC.Items.FindByValue("B").Selected = True

or

RBC.SelectedValue = 2

Grz, Kris.

XIII
`FindByValue` is not a member of RadioButtonList (ERROR) ?? !! %%
dotNET
I can't use the second response because I don't know what will the user choose.
dotNET
My bad, it's the items list bound to the radiobuttonlist, or any list control, which exposes the FindByValue method. I corrected my initial reply.
XIII
Thanks it's worked.
dotNET
A: 

On aspx-Page:

 <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem>A</asp:ListItem>
        <asp:ListItem Selected="True">B</asp:ListItem>
        <asp:ListItem>C</asp:ListItem>
        <asp:ListItem>D</asp:ListItem>
 </asp:RadioButtonList>

In Codebehind:

Dim item As New ListItem("A", "A")
Me.RadioButtonList1.Items.Add(item)
item = New ListItem("B", "B")
item.Selected = True
Me.RadioButtonList1.Items.Add(item)
item = New ListItem("C", "C")
Me.RadioButtonList1.Items.Add(item)
item = New ListItem("D", "D")
Me.RadioButtonList1.Items.Add(item)

or

Me.RadioButtonList1.SelectedValue = "B"
Tim Schmelter