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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reloading a page if recordset returns no records

Status
Not open for further replies.

david7777777777

Programmer
Sep 26, 2001
417
US
I have an ASP page with a listbox, 2 recordsets, a button, and a grid.

rsLocations
rsShipments
lstDestination
btnGo


The page allows users to select a location/destination and use their selection from the lstDestination drop-down box as the search criteria for the rsShipments recordset, which returns all shipments shipped to that destination.

When the page first loads, all that is visible is the drop-down box and the btnGo button. Once they select a destination from the drop-down box, they click the Go button, which displays the appropriate records in the grid.

If the rsShipments recordset returns no records, I have a little message displaying telling the user to click the hyperlink in another frame to the left. This reloads the page from scratch.

What I want to do is eliminate that step for the user and have the page automatically reload if the recordset returns no records, along with the message "No records found, try again."

Here is the code if the recordset is empty:

Sub rsShipments_ondatasetchanged()
if rsShipments.BOF and rsShipments.EOF then
response.write &quot;<P><br>&nbsp;<font color=red><b>No shipments found.</font></b></P>&quot;
end if
End Sub

Thanks for your help.
 
1. If you use onchange event of the combo, then you would not need the GO button.

2. The SQL for the destinations list could determine if there would be any Shipments - and include this in the dropdown text, or to remove the entries from the list.

3. The test for the empty recordset should be in the button click or the onchange event - as this is where you close the rsShipments (if open) set the rsShipments parameter and open the recordset.

4. The grid would be on the same page as the combo, and would naturally hide when the recordset is empty. You can alter the DATAGRID.ASP to store a message to display when empty - and set this to blank on initial page load, and to your 'Sorry' message on GO click. Or you could add a Label DTC for your message (which holds its value between server round-trips). Or add a global message variable (ie not contained within any function/sub in the page code), and set this as appropriate. It will get printed when you add
<%=m_sMessage%>
this assumes that the message is called m_sMessage (the m_ prefix is for 'module wide').

5. This way the user does not need to refresh anything - they just select different destinations and the grid appears below as appropriate. (Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top