Wednesday, March 21, 2012

Passing a parameter to another page

On one page I have a datagrid which is filled when the user selects some search criteria (e.g. surname or DoB) in different text fields and clicking on a button control.

The datagrid also contains a 'button column' which the user can use to edit and save changes to individual records to the db.

I use the following code to access the PK of the table in question as a parameter for my update query:

Dim strPatID As String = e.Item.Cells(0).Text

strSQL = "UPDATE blah "
strSQL = strSQL & "SET blah blah blah"
strSQL = strSQL & "WHERE patid = '" & strPatID & "'"

All of this works fine.

However, I also want users to be able to add records to a related table (which is at the many end of a relationship) based on the record they've selected from the datagrid. I've set up a 'hyperlink column' in the same datagrid which redirects them to another page where they'll be able to add data and save it. Fine so far.

The problem is of course, I need the patid as the foreign key to this second table. How can I pass this as a parameter to the second page? Am I doing this the right way or is there a better way to add records to related tables?

I hope I've made myself clear. Please let me know if you need additional information.

Thanks in advance for any help.

MoYou could pass it in the querystring to the new page:

DetailEntry.aspx?PatID=xxxxxx

On the second page, you can use Request.Querystring("PatID") to get the value
Thanks very much for the response Jim. I'll try it out.
Best regards to JimRoss:

In addition to using QueryString, you can also think of :

Session Variables as another solution, in addition to the other solutions.

regards

0 comments:

Post a Comment