Building text box name programically

S

sck10

Hello,

I am inserting the values for radio buttons on a form into a database.
There are 25 questions with 4 possible answers (see below). Is it possible
to pragmatically build the radio button name so I can loop through the
possibilities?

For example I would like to be able to build the rbn [01 - 25] in a loop
for:

If Me.rbn01q01.Checked = True Then strRad01 = "Poor"
If Me.rbn01q02.Checked = True Then strRad01 = "Satisfactory"
If Me.rbn01q03.Checked = True Then strRad01 = "Good"
If Me.rbn01q04.Checked = True Then strRad01 = "Excellent"
If Len(strRad01) <> 0 Then Call DBInsertUpdate("sp_web_Survey",
strDateStamp, Me.lblQ01.Text, strRad01)
....
If Me.rbn25q01.Checked = True Then strRad25 = "Poor"
If Me.rbn25q02.Checked = True Then strRad25 = "Satisfactory"
If Me.rbn25q03.Checked = True Then strRad25 = "Good"
If Me.rbn25q04.Checked = True Then strRad25 = "Excellent"
If Len(strRad25) <> 0 Then Call DBInsertUpdate("sp_web_Survey",
strDateStamp, Me.lblQ01.Text, strRad25)
 
S

Steven Cheng[MSFT]

Hi Sck10,

Thank you for posting in the ASP.NET newsgroup.

From your description, I understand you're building an ASP.NET web page
which contains many radio buttons and these radio buttons are associated to
many "survey questions"(four buttons per question. Currently you're
wondering how to programmatically loop through all those radio buttons on
the page and save their status information into backend database, correct?

Based on my experience, you can consider using template databound control
to display those radio buttons (grouped by survey questions). This is
because template databound control support displaying list of control
region through databinding. Therefore, in your case, you can put four radio
buttons in the template databound control's Template and bind it with a
datasource which contains the survey question list. e.g.

=========================
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<br /><asp:Label ID="lblQuestion" runat="server" Text='<%#
Eval("Question") %>'></asp:Label><br />

<asp:RadioButton ID="a1" Text="Answer 1" runat="server" />
<asp:RadioButton ID="a2" Text="Answer 2" runat="server" />
<asp:RadioButton ID="a3" Text="Answer 3" runat="server" />
<asp:RadioButton ID="a4" Text="Answer 4" runat="server" />
<br /><hr />
</ItemTemplate>
</asp:Repeater>
=============================

The above repeater control uses the "ItemTemplate" to define the control
region for each survey question. You can simply generate a datasource
containing all the questions and bind it to the repeater at runtime. Also,
if you need further customization on the repeater or each repeater item,
you can use the "ItemDataBound" event.

In addition, if you don't want to use databinding based solution, you can
also consider using the table control (html table or asp.net table control)
to display the radiobuttons and each table row contains the radio buttons
associated with a certain question.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top