Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Master child display

Status
Not open for further replies.

somas

MIS
Feb 10, 2004
1
IN
Hi,
I have a asp page which needs to have a list box at the upper half of the page which will bring up the list of departments. Now I have that working. When the user selects a department, it should populate all the employees for that dept in the lower half of the screen. I have the SQL for this. But am not able to figure out how I can pass the dept_id (selected by the user from the list) as a parameter for the query that populates the employees list below. Please help. It is a live or die scenario here!! Thanks in advance
 
Either the querystring or a form field usually passes the value. Suppose we do it with a querystring. Each department listed should have the value attached to the link like this:

<a href=&quot;page.asp?deptID=56&quot;>deptname</a>

To get the ID in there you insert it when you list your departments. Suppose your query goes:

[red]set rec = conn.execute(&quot;SELECT * FROM departments&quot;)[/red]

you then would loop through the query and insert the ID each time through the loop:

[red]do while NOT rec.EOF
[tab]response.write(&quot;<a href='page.asp?deptID=&quot;&rec(&quot;deptID&quot;)&&quot;'>&quot;&rec(&quot;deptName&quot;)&&quot;</a><br>&quot;)
[tab]rec.movenext
loop[/red]

Then when the user clicks one of these links the querystring will pass the value to the page and you then do your SQL (later in the same page) like this:

[red]
set rec = conn.execute(&quot;SELECT * FROM employees WHERE deptID=&quot;&request.querystring(&quot;deptID&quot;))
do while NOT rec.EOF
[tab]response.write(&quot;<a href='page.asp?deptID=&quot;&rec(&quot;deptID&quot;)&&quot;'>&quot;&rec(&quot;deptName&quot;)&&quot;</a><br>&quot;)
[tab]rec.movenext
loop[/red]


Also you want to distinguish between two cases:

1. page.asp just shows the departments
2. page.asp shows the departments at the top as well as the employees at the bottom

case two only occurs when a user selects a department so you want to check whether request.querystring(&quot;deptID&quot;) has a value or you can assign an additional querystring flag like:

<a href=&quot;page.asp?deptID=56&action=showEmp&quot;>deptname</a>

the check should be an enclosing if around the employee query. Also the word &quot;populate sometimes suggests javascript so that there is no page reload but I don't think that's what you mean and that is a bit of overkill for something like this.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top