开发者

RadioButtonList on ASP.NET (VB)

开发者 https://www.devze.com 2023-01-04 05:41 出处:网络
I have a RadioButtonList which contain 4 radio buttons A,B,C,D RBQ.Items.Add("A") RBQ.Items.Add("B")

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"
0

精彩评论

暂无评论...
验证码 换一张
取 消