how to set FormView RadioButtonList via code behind

Hi, how do I set a formview radiobutton to item 1 or item 2 via vb code-behind ?.

i.e. AdFormView.FindControl("radioButtons")
LVL 1
Netlink2Asked:
Who is Participating?
 
RedKelvinConnect With a Mentor Commented:
did you try?

me.forviewName.RadioButtonList1
0
 
RedKelvinCommented:
Hi, if you place a radiobuttonlist on your form like this

<asp:RadioButtonList id="RadioButtonList1" runat="server" />

You can then manipulate it directly using the codebehind, this will add 2 radio buttons to the list

    Me.RadioButtonList1.Items.Add("MyItem1")
    Me.RadioButtonList1.Items.Add("MyItem2")


This will change the display text and set the value of the first item

    Me.RadioButtonList1.Items(0).Text = "MyItem3"
    Me.RadioButtonList1.Items(0).Value = "MyValue3"

The .items is an array, so the element must exist to modify it.

RedK
0
 
Netlink2Author Commented:
I tried your suggestion, I get the error, radiobutton is not a member of aspx.
Also, how do I select which item is active, i.e. how to set a radio button as the current defualt ?.
I guess that this is because it's part of a formview. It's inside of the following code:

<asp:FormView ID="AdFormView" runat="server" DataSourceID="AdDataSource" DefaultMode="Edit"
DataKeyNames="Id" OnItemUpdating="AdFormView_ItemUpdating">

The code is:

<asp:RadioButtonList  runat="server" ID="radioGarage">
      <asp:ListItem Value="1" >Yes</asp:ListItem>
      <asp:ListItem Value="2" Selected="True">No</asp:ListItem>
</asp:RadioButtonList>
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
RedKelvinCommented:
you probably got that error if you pasted the code in the markup page, try dropping the radiobuttonlist control on the form from the toolbox, that way it will be added to the .designer page.

To set a list item as selected use the following, this will set the first item as selected

    Me.RadioButtonList1.Items(0).Selected = True

To enable/disable an item you can use

    Me.RadioButtonList1.Items(0).Enabled = True
0
 
Netlink2Author Commented:
I tried using Me.RadioButtonList1 etc, but I get the error, radiobutton is not a member of aspx. I think that this is because it's a part of an asp:FormView.
0
 
RedKelvinCommented:
can you use
me.forviewName.RadioButtonList1

Take a peek at this too
http://www.thescripts.com/forum/thread506624.html
0
 
Netlink2Author Commented:
Sorry RedKelvin, that link took me nowhere.
0
 
Netlink2Author Commented:
I gave up on trying, I just changed the radio button to a checkbox.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.