Monday, March 26, 2012

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.
ThanksIf they are plain HTML radio buttons, you can't loop through them in
server-side code. It must be done from client-side code.
"Brian" <bciarcia@.pepehazard.com> wrote in message
news:1109213918.751967.126580@.f14g2000cwb.googlegroups.com...
>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
>
Can you elaborate on looping through radio buttons?
If the radio buttons are defined by you, why do you need to loop
through them after submission? And you can select only one item in a
radiobutton-group.
Can you give an example of what you are trying to achieve? That may
help in analysing the problem better.
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
--
to get most of the help in this group, you better post a try of ur code.
asking plain questions like this usually is missleading or says that you
haven't tried anything in the first place.
why don't u try to do it in ur own code and post ur code so u can have
better guidance. i hope u find the answer as soon as possible ;)
"Brian" <bciarcia@.pepehazard.com> wrote in message
news:1109213918.751967.126580@.f14g2000cwb.googlegroups.com...
>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
>
Thanks for the replies... Ok.. I have 8 groups of questions. I'll post
a sample of one group below. Depending on who logs in, will depend on
how many groups of questions they will get. Once they check either the
yes or no radio button for each question, the will submit the form. I
will need to know how many questions there are, then loop through those
questions and input them into the db. for example( if two of the
questions were "the sky is blue" and "the ocean is green".. One record
will be created for the first question, and another record will be
created for the second question). I also need to know if any answers
were answered yes, but that is a separate issue. Right now, I just need
to know how to do this part... Here is a sample of the questions. These
are being stored in a questions table in the db.
---
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<th noWrap>
<div align="center"><span class="style3">Coronary Artery Disease
</span></div></th>
<th><span class="style3">YES</span></th>
<th><span class="style3">NO</span></th></tr>
<tr>
<td noWrap width="69%"><span class="style3">Have you ever received a
diagnosis of heart disease or coronary artery disease?</span></td>
<td width="6%">
<div align="center">
<input type="radio" value="yes" name="CAD_1" /> </div></td>
<td width="6%">
<div align="center">
<input type="radio" value="no" name="CAD_1" /> </div></td></tr>
<tr>
<td class="style3" noWrap>Have you ever had a heart attack?</td>
<td>
<div align="center">
<input type="radio" value="yes" name="CAD_2" /> </div></td>
<td>
<div align="center">
<input type="radio" value="no" name="CAD_2" /> </div></td></tr>
<tr>
<td class="style3" noWrap>Have you ever been treated for a blocked atery
anywhere in your body? </td>
<td>
<div align="center">
<input type="radio" value="yes" name="CAD_3" /> </div></td>
<td>
<div align="center">
<input type="radio" value="no" name="CAD_3" /> </div></td></tr>
<tr>
<td class="style3" noWrap><span class="style4">Have you ever been
treated for chest pain caused by blockage of arteries in your heart?
</span></td>
<td>
<div align="center">
<input type="radio" value="yes" name="CAD_4" /> </div></td>
<td>
<div align="center">
<input type="radio" value="no" name="CAD_4" /> </div></td></tr>
<tr>
<td class="style3" noWrap><span class="style4">Have you ever had an
abnormal exercise tolerance test (ETT, stress test) </span></td>
<td>
<div align="center">
<input type="radio" value="yes" name="CAD_5" /> </div></td>
<td>
<div align="center">
<input type="radio" value="no" name="CAD_5" />
</div></td></tr></tbody></table>
---
I am just querying the db and grabbing the appropriate groups.. The
names of the radios are important too, per the customers request.
Another group would be CHF_1,CHF_2, etc.. If anyone knows a better way
of doing this, I'll be glad to hear it... Let me know if you need
anymore detail..
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
If there are only 8 questions (and each radio button in a group are all
named the same name), you don't need to loop at all. Just check all 8
groups to see if a group has a value. If a group has a value, then that
question was responded to.
Or, since they are submitting the data to the server, you could just check
the Request object in the same way to see what data was submitted.
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:e%23hIL2lGFHA.1096@.tk2msftngp13.phx.gbl...
> Thanks for the replies... Ok.. I have 8 groups of questions. I'll post
> a sample of one group below. Depending on who logs in, will depend on
> how many groups of questions they will get. Once they check either the
> yes or no radio button for each question, the will submit the form. I
> will need to know how many questions there are, then loop through those
> questions and input them into the db. for example( if two of the
> questions were "the sky is blue" and "the ocean is green".. One record
> will be created for the first question, and another record will be
> created for the second question). I also need to know if any answers
> were answered yes, but that is a separate issue. Right now, I just need
> to know how to do this part... Here is a sample of the questions. These
> are being stored in a questions table in the db.
> ---
> <table cellspacing="0" cellpadding="0" width="100%" border="0">
> <tbody>
> <tr>
> <th noWrap>
> <div align="center"><span class="style3">Coronary Artery Disease
> </span></div></th>
> <th><span class="style3">YES</span></th>
> <th><span class="style3">NO</span></th></tr>
> <tr>
> <td noWrap width="69%"><span class="style3">Have you ever received a
> diagnosis of heart disease or coronary artery disease?</span></td>
> <td width="6%">
> <div align="center">
> <input type="radio" value="yes" name="CAD_1" /> </div></td>
> <td width="6%">
> <div align="center">
> <input type="radio" value="no" name="CAD_1" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap>Have you ever had a heart attack?</td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_2" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_2" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap>Have you ever been treated for a blocked atery
> anywhere in your body? </td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_3" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_3" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap><span class="style4">Have you ever been
> treated for chest pain caused by blockage of arteries in your heart?
> </span></td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_4" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_4" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap><span class="style4">Have you ever had an
> abnormal exercise tolerance test (ETT, stress test) </span></td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_5" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_5" />
> </div></td></tr></tbody></table>
> ---
> I am just querying the db and grabbing the appropriate groups.. The
> names of the radios are important too, per the customers request.
> Another group would be CHF_1,CHF_2, etc.. If anyone knows a better way
> of doing this, I'll be glad to hear it... Let me know if you need
> anymore detail..
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
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.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
try to put the group of radio buttons in a web control PlaceHolder, make
those radio buttons Web controls instead of HTML in that PlaceHolder.
then you can use :
foreach( Control c in placeHolder.Controls )
{
//cast the control to web radio button and do what ever u like with it
}
i hope this helps
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:e%23hIL2lGFHA.1096@.tk2msftngp13.phx.gbl...
> Thanks for the replies... Ok.. I have 8 groups of questions. I'll post
> a sample of one group below. Depending on who logs in, will depend on
> how many groups of questions they will get. Once they check either the
> yes or no radio button for each question, the will submit the form. I
> will need to know how many questions there are, then loop through those
> questions and input them into the db. for example( if two of the
> questions were "the sky is blue" and "the ocean is green".. One record
> will be created for the first question, and another record will be
> created for the second question). I also need to know if any answers
> were answered yes, but that is a separate issue. Right now, I just need
> to know how to do this part... Here is a sample of the questions. These
> are being stored in a questions table in the db.
> ---
> <table cellspacing="0" cellpadding="0" width="100%" border="0">
> <tbody>
> <tr>
> <th noWrap>
> <div align="center"><span class="style3">Coronary Artery Disease
> </span></div></th>
> <th><span class="style3">YES</span></th>
> <th><span class="style3">NO</span></th></tr>
> <tr>
> <td noWrap width="69%"><span class="style3">Have you ever received a
> diagnosis of heart disease or coronary artery disease?</span></td>
> <td width="6%">
> <div align="center">
> <input type="radio" value="yes" name="CAD_1" /> </div></td>
> <td width="6%">
> <div align="center">
> <input type="radio" value="no" name="CAD_1" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap>Have you ever had a heart attack?</td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_2" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_2" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap>Have you ever been treated for a blocked atery
> anywhere in your body? </td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_3" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_3" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap><span class="style4">Have you ever been
> treated for chest pain caused by blockage of arteries in your heart?
> </span></td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_4" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_4" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap><span class="style4">Have you ever had an
> abnormal exercise tolerance test (ETT, stress test) </span></td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_5" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_5" />
> </div></td></tr></tbody></table>
> ---
> I am just querying the db and grabbing the appropriate groups.. The
> names of the radios are important too, per the customers request.
> Another group would be CHF_1,CHF_2, etc.. If anyone knows a better way
> of doing this, I'll be glad to hear it... Let me know if you need
> anymore detail..
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
Im sorry.. I'm really ignorant when it comes to this... How do I put it
in a placeholder? can I still store the groups in the database' I
feel like such an idiot now..
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
you are not idiot at all, all what you need is more reading. go to the msdn
and read more about the place holder :)
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:egVPsonGFHA.3876@.TK2MSFTNGP14.phx.gbl...
> Im sorry.. I'm really ignorant when it comes to this... How do I put it
> in a placeholder? can I still store the groups in the database' I
> feel like such an idiot now..
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!

0 comments:

Post a Comment