Select and display by checking a checkbox

Results 1 to 2 of 2

Thread: Select and display by checking a checkbox

  1. #1
    Join Date
    Dec 1969

    Default Select and display by checking a checkbox

    I retrieve records from a DB and display them on another page. These records have checkboxes besides them. In order to modify these records i will have to select some records by checking the checkboxes and click on the modify button. On clicking this button only those records should go onto the next page and should be displayed on textboxes where i can make the changes and update the records. How do i make them display only the selected records?? Please let me know

  2. #2
    Join Date
    Dec 1969

    Default RE: Select and display by checking a checkbox

    First page:<BR><BR>You create the checkbox lines in a loop on a RecordSet, presumably. Something like:<BR><BR>&#060;% <BR>Do Until RS.EOF <BR> &nbsp; Response.Write "&#060;INPUT Type=&#039CheckBox&#039 Name=&#039Edit&#039 Value=&#039" & RS("primaryKeyField") & "&#039&#062;" <BR> &nbsp; ... other fields? ...<BR> &nbsp; RS.MoveNext<BR>Loop <BR>%&#062;<BR><BR>The important point there is to be sure<BR>(1) All checkboxes have the same name (&#039Edit&#039 here, but your choice.)<BR>(2) The value of each checkbox is the primary key of the record you will want to edit.<BR><BR>*******************<BR><BR>On page 2:<BR><BR>&#060;%<BR>&#039 this gets the list of primary keys as a comma-delimited list<BR>temp1 = Request.Form("Edit")<BR><BR>&#039 convert from COMMA-SPACE to APOSTROPHE-COMMA-APOSTROPHE<BR>temp2 = Replace( strRecords, ", ", "&#039,&#039" )<BR><BR>&#039 tack on leading and trailing apostrophes:<BR>strRecords = "&#039" & temp2 & "&#039"<BR><BR>&#039 now create the SQL statement:<BR>SQL = "SELECT * FROM table WHERE primaryKeyField IN (" & strRecords & ")"<BR><BR>...<BR>%&#062;<BR><BR>And that SELECT statement will automagically get all the records selected by the user when she/he checked the checkboxes on the prior page.<BR><BR>There are *LOTS* of other ways to do this, but I think you&#039ll find this one is the most efficient!<BR><BR>You can even do it all in a single VBS statement if you don&#039t like typing:<BR><BR>&#060;%<BR>SQL = "SELECT * FROM table WHERE primaryKeyField IN (&#039" & Replace(Request("Edit"),", ","&#039,&#039") & "&#039)"<BR>%&#062;<BR><BR>Which works but is really ugly, isn&#039t it?<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts