?
Solved

how to set FormView RadioButtonList via code behind

Posted on 2007-10-21
8
Medium Priority
?
465 Views
Last Modified: 2012-05-05
Hi, how do I set a formview radiobutton to item 1 or item 2 via vb code-behind ?.

i.e. AdFormView.FindControl("radioButtons")
0
Comment
Question by:Netlink2
  • 4
  • 4
8 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20119663
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
 
LVL 1

Author Comment

by:Netlink2
ID: 20120358
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
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20120617
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Netlink2
ID: 20121216
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
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20122294
can you use
me.forviewName.RadioButtonList1

Take a peek at this too
http://www.thescripts.com/forum/thread506624.html
0
 
LVL 1

Author Comment

by:Netlink2
ID: 20143726
Sorry RedKelvin, that link took me nowhere.
0
 
LVL 22

Accepted Solution

by:
RedKelvin earned 2000 total points
ID: 20146381
did you try?

me.forviewName.RadioButtonList1
0
 
LVL 1

Author Comment

by:Netlink2
ID: 20286243
I gave up on trying, I just changed the radio button to a checkbox.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question