RadioButtonList on ASP.NET (VB)
I have a RadioButtonList which contain 4 radio buttons A,B,C,D
RBQ.Items.Add("A")
RBQ.Items.Add("B")
RBQ.Items.Add(&quo开发者_JS百科t;C")
RBQ.Items.Add("D")
How can set the selected value to the radio button who has the value "B"?
RBC.Items.FindByValue("B").Selected = True
or
RBC.SelectedValue = 2
Grz, Kris.
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"
精彩评论