Forums
This topic is locked
ASP.NET VB - Create a LOOP to insert checkboxes
Posted 18 Nov 2006 03:37:46
1
has voted
18 Nov 2006 03:37:46 Mike Mitchell posted:
I'm working on a .NET project (written in VB using Dreamweaver against an SQL 2003 server).THE SCENARIO:
I have a form where the users selects their interests (baseball, computing, video games, cooking, etc.). The user clicks the appropriate checkboxes and the form INSERTS one record for each item checked (it's stored in a many-to-many table, along with the User's ID, the datestamp, and a few other items).
Now, a few things first:
1) The list is dynamic (pulled from a db table).
2) I am using a repeat region to create the list.
3) Each checkbox does have a unique name (based on the item's ID number):
<pre id=code><font face=courier size=2 id=code>
<input name="ckRec_<%# dsGetAnswer.FieldValue("AnswerID", Container) %>" type="checkbox" id="ckRec_<%# dsGetAnswer.FieldValue("AnswerID", Container) %>" value='<%# dsGetAnswer.FieldValue("AnswerID", Container) %>' onClick="setGoToValue(<%# dsGetAnswer.FieldValue("AnswerGoTo_QuestionID", Container) %><img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>;">
</font id=code></pre id=code>
I have done this in classic ASP, but am having trouble getting it to work in ASP.NET.
Here's the code I have used in CLASSIC ASP (just ignore the names in the SQL INSERT statement -- they're old):
<pre id=code><font face=courier size=2 id=code>
' ------------------------------------------------------------------------
' ----------------------- START CUSTOM INSERT LOOP ----------------------
' ------------------------------------------------------------------------
' Create the connection
Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_databaseConnection_STRING
for each field in Request.Form
If mid(field,1,6) = "ckRec_" AND len(request.form(field)) > 0 then
intRecipiesID=mid(field,7,len(field)) ' Get the AMID if the item is clicked
intQuantityVar=Request.Form("qtRec_" & inItemID)
intSplitVar=Request.Form("spRec_" & inItemID2)
strSQL = "INSERT INTO Response(AMID, OC_MC_RecipiesID, OCQuantity, OCIsSplit) values ('" & intOrdersID & "', '" & intRecipiesID & "', '" & intQuantityVar & "', '" & intSplitVar & "' )"
MM_editCmd.CommandText = strSQL
MM_editCmd.execute strSQL
end if
next
' ------------------------------------------------------------------------
' ------------------------ END CUSTOM INSERT LOOP -----------------------
' ------------------------------------------------------------------------
</font id=code></pre id=code>
Can you guys give me a hand with the .NET syntax and approach?
Also, I would LOVE to use a CheckBoxList instead, but I've had even less luck with that.
Thanks in advance.