NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

Working with Multiple Checkboxes, Revisited

Written by Eric Smith, Northstar Computer Systems LLC

This tip was sent out with a slight error. The fourth line previously checked Request(item.Name) instead of Request(item.Value) as it should have. Thanks to Jay Burrill who caught this typo.

In an application I’m writing, I have a form that shows a large number of checkboxes to the user. These checkboxes each become a record in a database table related to the primary entity. In order to make it easy to insert the appropriate records for the main record, I created a naming structure for each box based on it primary key of the value shown by the checkbox. Prefixing the name with “dbchk” makes it easier to find when looping through the Request collection. Once I determine if the box was checked, I call a stored procedure to insert the record into the table. Here’s an example of how to check the value, assuming the name is dbchkValue##, which ## being the number of the category.


Dim item   ‘ As Variant
For Each item in Request.Form
   If Left(item.Name, 5) = “dbchk” Then
      If Request(item.Value) = “Y” Then
         dcnDB.Execute(“sp_AddRecordToTable “ & Mid(item.Name, 11))
      End If
   End If
Next ‘ item
This will automatically insert a row into the table for each check box that is marked. It also saves you from having to write lots of redundant code to insert particular rows into the table.

Keywords: [ Uncategorized ASP Tips ]

Publication Date: 6/1/2000