This topic is locked

Default Add Value

7/17/2006 8:23:24 PM
ASPRunnerPro General questions
author

Long time ASPRunner fan trying to push the envelope a little, with very little asp skills.
I am trying to pass a value from the Master table at the top of the _list.asp page to be used as a default value in the _Add.asp page. I suspected I may be able to do it in events, but do not know how.
Thanks!

J
Jane 7/18/2006

Hi,
sure, you can do it using events.

Proceed to the Events tab, select ListOnLoad event and put following code in it:

Sub ListOnLoad(strSQL)

str = "select * from MasterTable where FieldID="&strMasterKey

set rs = server.CreateObject("ADODB.Recordset")

rs.open str, dbConnection

Session("FieldName") = rs("FieldName")

End Sub



where MasterTable is your actual table name, FieldID is a foreign key in the master table, FieldName is your actual field name.
Then set Session("FieldName") as default value for the FieldName on the Edit format dialog on the Formatting tab.

501267 7/19/2006

Thanks so much it works great! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=9913&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

501268 7/26/2006

This works great, but I need it to do one more trick. How can I have it pass more than one value? For example, I need to set the default on the add page to the value of Field1, Field2 and Field3 from the list page?
Thanks again for the wonderful help,
EV

Hi,

sure, you can do it using events.

Proceed to the Events tab, select ListOnLoad event and put following code in it:
where MasterTable is your actual table name, FieldID is a foreign key in the master table, FieldName is your actual field name.
Then set Session("FieldName") as default value for the FieldName on the Edit format dialog on the Formatting tab.

Alexey admin 7/27/2006

Hi,
use this code in ListOnLoad event:

Sub ListOnLoad(strSQL)

str = "select * from MasterTable where FieldID="&strMasterKey

set rs = server.CreateObject("ADODB.Recordset")

rs.open str, dbConnection

Session("FieldName") = rs("FieldName")

Session("FieldName1") = rs("FieldName1")

Session("FieldName2") = rs("FieldName2")

...


End Sub


and Session("Fieldname1") , Session("Fieldname2") etc as default values for your fields.

501269 7/27/2006

I tried something like that, but close only counts in horse shoes and hand grenades! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10075&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' /> You make my little heart go pitter patter - it worked wonderfully as I am sure is no surprise to you.
EV

Hi,

use this code in ListOnLoad event:
and Session("Fieldname1") , Session("Fieldname2") etc as default values for your fields.