473,786 Members | 2,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop through a Plain Radio Button in ASP.NET

I have a list of plain HTML radio buttons that I want to be able to
loop through, get the values from them and insert them into a db. each
one should be a separate record... Can anyone please give me some kind
of example on how to do this???? I am doing this in asp.net VB.
Please let me know if you need any additional information.

Thanks

Nov 19 '05
33 3663
Brian,

If you use standard HTML radio buttons (<INPUT TYPE="radio">), then you
should name all the radio buttons for a given question the same name. That
way each question will have exactly ONE radio button that holds the answer
to the question. With standard HTML radio buttons, this is also what gives
them their mutual exclusivity.

As I said earlier, since the answers to all the questions that were asked
are going to be sent to the server via a submit, you can just query the
Request object to see what data it contains. By doing this, you will know
which questions were asked since only those answers would have been sent to
the server.

[VB.NET]
Dim answer as String
For Each Answer In Request.Form
'references to answer return the name of the item
'references to Request.Form(an swer) refer to the value of the item
Next

-Scott

"Brian Ciarcia" <bc******@pepeh azard.com> wrote in message
news:Ok******** ******@TK2MSFTN GP14.phx.gbl...
Actually, it is 8 groups of questions and the names are different..
(ie.. group one.. the names are CAD_1,CAD_2,CAD _3 group two.. the names
are CHF_1,CHF_2,CHF _3,CHF_4. etc..) Each group has a different number
of questions. Each question has to have an answer, either yes or no..
Since this is an asp.net page, I have no clue How to get the answers
into the database. CAD_1 has to have its own record, CAD_2 has to have
its own record, etc, etc.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #11
Scott,

Thanks... I swear I tried something like that before, but it didn't
work.. I just tried it using your code and it works great.. So now I am
looping through the questions when I submit to another page. Can I put
that code in the codebehind on this page, or does this form have to be
submitted to another page? If so, can I add this code to the codebehind
on the submission page???

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #12
In ASP.NET server-forms submit to the same page. You can add this code to
whatever code-behind you submit to.

You may want to use the Web Forms Panel control to hold the 8 groups of
questions (you'll need 8 panel controls). Then it is simply a matter of
setting the visible property of the correct panel to true and all others to
false. This way you can do all your work in one .aspx page with just one
code-behind.

"Brian Ciarcia" <bc******@pepeh azard.com> wrote in message
news:eg******** ******@TK2MSFTN GP15.phx.gbl...
Scott,

Thanks... I swear I tried something like that before, but it didn't
work.. I just tried it using your code and it works great.. So now I am
looping through the questions when I submit to another page. Can I put
that code in the codebehind on this page, or does this form have to be
submitted to another page? If so, can I add this code to the codebehind
on the submission page???

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #13

Ok.. I'll look into the web form panel... do you know where I can find
any reading on that??
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #14

Ok.. I'll look into the web form panel... do you know where I can find
any reading on that??
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #15
If I use the panels, do I then have to change the radio buttons to
asp:radiobutton s or can I keep them as regular buttons?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #16
You can use any controls on a panel that you like.

"Brian Ciarcia" <bc******@pepeh azard.com> wrote in message
news:ec******** ******@TK2MSFTN GP12.phx.gbl...
If I use the panels, do I then have to change the radio buttons to
asp:radiobutton s or can I keep them as regular buttons?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #17

ok.. i know you probably think I am a pain in the _ss right now, but to
control the visibility of those panels, would I do something like this?

I set the Panel ID's to be CAD, HB, CHF, DBTS. The customer I am
pulling up only should see CAD and HB.
foreach( Control c in Panel.Controls )

If (objBarDataRead er("ProgramID" ) = Panel(c) then

Panel(c).visibi lity = "true"
end if

next

Is that Close?????
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #18

I got it.. I did this;
Dim ctl as Control

For Each ctl In Page.Controls
If TypeOf (ctl) Is System.Web.UI.W ebControls.Pane l Then

If ctl.ID = objBarDataReade r("ProgramID" ) Then
ctl.visible = True
End If
End If
Next

------------------------------------------------------

That worked.. Ok.. so now when I hit submit, I just create an onclick
event and put that code that you gave me earlier in there, correct?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #19
I just added this code to my codebehind and now my questions wont
display.. Am I doing something wrong??

I created an asp:button called LoginButton and created a label called
errormessage.

I am just trying to display the results so I can see what is happening.

------------------------------------------------------

Private Sub LoginButton_Cli ck(ByVal sender as System.Object, ByVal e as
System.EventArg s) Handles LoginButton.Cli ck

Dim answer as String
Dim AnsStr
For Each Answer In Request.Form
'references to answer return the name of the item
AnsStr = AnsStr & "the answer to question " & answer & " is " &
Request.Form(an swer) & "<br>"
Next
errormessage.Te xt = AnsStr
end sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3282
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1> <input type="radio" name=p2 value=2> <input type="radio" name=p2 value=3> then a text area and a button:
6
1679
by: Ed Jay | last post by:
<disclaimer>New to js.</disclaimer> I have several pages, each with menues comprising checkboxes or radio boxes within the same form. I presently 'brute force' clear the buttons with individual scripts for each form, e.g.: function clearLa() { window.document.form1.button1La.checked=false; window.document.form1.button2La.checked=false; window.document.form1.button3La.checked=false;
9
9305
by: wreed | last post by:
I have a for loop seen below.... var the_form = document.getElementById(formName); for(var i=0; i<the_form.length; i++) { var temp = the_form.elements.type; if (temp == "radio") { for (x = 0; x < the_form.elements.length - 1; x++) {
9
2254
by: IchBin | last post by:
I can not see what the problem is with this script. I am just trying to set a radio button by calling setCheckedValue('abbr_letter', 'V'). Sorry I am new to javascript. <html> <head> <script type="text/javascript"> function setCheckedValue(radioObj, newValue) { if(!radioObj)
10
6104
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
8
6767
by: romano2717 | last post by:
I used the for loop variable $i to each radio button so that each radio button will have a unique name. the problem now is how can i display the values selected in the radio button on the same page as where the form is located. your help is greatly appreciated.. thanks here's the code: NOTE: this code is cut short, i only posted the part where i got stuck <?php if(isset($_GET)){ $num = $_GET; $num = 2; for($i=1; $i<=$num; $i++...
2
21500
by: somacore | last post by:
VS2005, C# Windows Form I can't quite figure out how to do this, but i think I'm close. I have a groupbox which contains 8 radio buttons, and I need to figure out which one is checked for entry into a database. The button field looks like this: ()Assigned ()Working ()In Testing and so on. In the DB, the values of the checkboxes are treated as an int, 0, 1, 2, 3 etc.
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.