VB 2.0 FORMSVIEW on a web form, how do I access the contents of the labels and radiobuttonlist?

Posted on 2007-08-03
Last Modified: 2013-11-26
I am new to VB.NET 2.0 and my great difficulty is accessing the contents of the labels on the FORMSVIEW
In the ItemTemplate.

I have a radiobuttonlist that I want to access the selected value of, normally this works but it does not work if the radiobuttonlist is on the FORMSVIEW.

Protected Sub RadioButtonList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList2.SelectedIndexChanged
        Session("myselection") = RadioButtonList2.SelectedValue.ToString
 End Sub

How can I access the value?

Thank you for your help.
Question by:GDene
    LVL 7

    Expert Comment

    I'm pretty sure with radio button list you actually need to look through each radio button and check to make sure if its selected or not.


    if radionButton1Label.checked = true then
    session("myselection") = radioButton1.text
    esle if if radionButton2Label.checked = true then
    2ession("myselection") = radioButton2.text
    end if
    LVL 16

    Accepted Solution

    In the declaration of your RadioButtonList2 in the aspx file, add the following attribute:

    Then change your event handler above to look exactly like this:
    Public Sub RadioButtonList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim RadioButtonList2 As RadioButtonList = DirectCast(FormView1.FindControl("RadioButtonList2"), RadioButtonList)
            Session("myselection") = RadioButtonList2.SelectedValue.ToString
     End Sub

    Make sure to replace "FormView1" with the id of your formview. Make sure that the function is declared as being Public, and make sure to get rid of the "Handles .... " part of the event handlers definition.

    Author Comment

    I dont know how many radio options there will be. The radiobuttonlist is bound to a accessdatasource so it will populate automatically
    I cannot access the simplist label.text on the Formsview. It has driven me to dispair.
    My reasearch on google has led be to believe that the only way to access things on the container FORMSVIEW is to use findcontrol.  Is this true?

    Dim myradio As RadioButtonList = CType(FormView1.FindControl("RadioButtonList1"), RadioButtonList)
    Session("myselection") = myradio.SelectedValue.ToString

    so if I want to refer to a label lke Name on the formsview I will have to
    Dim mylabel as Label = CType(FormVew1.FindControl("Name"), Label)
    Session("name") = mylabel.text

    That has driven me to sign up to get expert help

    Author Comment

    Dear TSmooth
    Thank you for your confirmation. I find it strange that such a good feature is so hard to work with.
    I thought as a beginner I was making it more difficult then it needed to be but now I can move on.
    Formsview is more hassle than it's worth.
    Too much work each time I want to access a field.

    LVL 7

    Expert Comment

    You could loop through all the controls on the page, test if they are radiobuttons and then see if they are selected.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now