This topic is locked

How to update selected records with value from dropdown box

11/19/2013 7:23:01 PM
ASPRunnerPro Tips and tricks
admin

This is a little more advanced version of "Update selected records" tutorial PHPRunner manual.
Lets say we have a list of orders and want to be able to update several orders at once selecting status from dropdown list on the same page. Statuses are stored in another table.


  1. To display a dropdown box with list of statuses proceed to the List page in Visual Editor and insert the Code Snippet where you need this dropdpown box to appear.

dim str, strSQL,rstmp

str = "<select id='mycontrol' value=''>Select status</option>"



strSQL = "SELECT Status from Statuses"

Set rstmp = server.CreateObject("ADODB.Recordset")

rstmp.open strSQL,dbConnection



while not rstmp.eof

str = str & "<option value='" & rstmp("Status") & "'>" & rstmp("Status") & "</option>"

rstmp.movenext

wend



str = str & "</select>"

Response.Write str



Make sure to amend the SQL query (select status from statuses) and field name (status).
2. Add a button next to this code snippet. Name it 'Update selected'.
Add the following to ClientBefore event:

// make sure user selected some value from dropdown box

if ($("#mycontrol").val()=="") {

alert('Choose something already');

return false;

}

// send the selected value to OnServer event

params['status']=$("#mycontrol").val();


Add the following code to OnServer part:

DoAssignment record, button.getNextSelectedRecord()

do while isObject(record)

sql = "Update Orders set Status='" & params("status") & "' where ID=" & record(ID)

dbConnection.Execute sql

DoAssignment record, button.getNextSelectedRecord()

loop


Amend OnServer code changing table name (Orders) and field names (Status and ID). Leave parameter name (params("status")) as is.
To refresh the page after updating selected records add the following code to ClientAfter event:

location.reload();


Enjoy!