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

Posted on 2007-08-03
Medium Priority
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
  • 2
  • 2

Expert Comment

ID: 19629225
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

TSmooth earned 2000 total points
ID: 19629228
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

ID: 19629289
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

ID: 19629338
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.


Expert Comment

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

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

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.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

864 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