Web Wiz - Solar Powered Eco Web Hosting

  New Posts New Posts RSS Feed - listing of records+combo box
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

listing of records+combo box

 Post Reply Post Reply
sankari View Drop Down

Joined: 22 January 2003
Location: India
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote sankari Quote  Post ReplyReply Direct Link To This Post Topic: listing of records+combo box
    Posted: 14 February 2003 at 5:05am


I've a combo box which allows the users to select the category using <select> tag. Depending on the category, I want to list specified number of records in a page. Here's the code.....


<% @ LANGUAGE="VBScript" %>


Option Explicit
Response.Buffer = True

Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adUseClient = 3
Const adCmdText = 1

' Variables for connection object, recordset, connection string, query string
Dim conn, rs, connString, qString,reno,cc

' Open the database connection
connstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connString%>

<HEAD>  <TITLE> Database paging </TITLE> </HEAD>
<form name=ss method=post action="category.asp">
<select name=cat onChange="MM_jumpMenu('parent',this,0)">
<option selected>choose category</option>
<option value="category.asp?cat=technical">Technical</option>
<option value="category.asp?cat=admin">Admin</option>
<option value="category.asp?cat=scientific">Scientific</option>
function MM_jumpMenu(targ,selObj,restore){ file://v3.0

  if (restore) selObj.selectedIndex=0;

<% if session("checked")="true" then

  Dim mypage, numpages, numrecs, pagesize

  ' Get the page number we need to display from Form or QueryString
  mypage = CInt( Request("page") )
  If mypage=0 Then mypage=1

  ' Get the requested number of records per page
  pagesize = CInt( Request("recs") )
  If pagesize = 0 Then pagesize = 2    ' If we aren't given a value use 10

  ' The code we need to set up a recordset object for paging
  Set rs = Server.CreateObject("ADODB.RecordSet")
  rs.PageSize = pagesize
  rs.CacheSize = pagesize  ' This is optional
  rs.CursorLocation = adUseClient
  ' Open the recordset
  qString = "SELECT * FROM staff where staffcategory='" & session("cat") & "'"

  rs.Open qString, conn, adOpenForwardOnly, adLockReadOnly, adCmdText

  ' Get the number of pages and records
  numpages = rs.PageCount
  numrecs = rs.RecordCount

  ' Just in case we have a bad request
  If mypage > numpages Then mypage = numpages
  If mypage < 1 Then mypage = 1

  ' Set the page we want to display
  rs.AbsolutePage = mypage

  ' Write out the total number of records in the recordset
  Response.Write("<P> <B>" & numrecs & " records found.</B>" )
  ' Write out the current page number and total number of pages
  Response.Write("<BR> Page " & mypage & " of " & numpages & "</P>")


  ' Write out the records contained in this page
  Dim i
  response.write("<table cellpadding=4 cellspacing=4 border=3>")
 For i=1 To pagesize
    If NOT rs.EOF Then
<a href="22.asp?option=<%=rs("CODE")%>">
   <%   response.write(rs("code"))
    End If


  ' Write out the page links
  Dim x, lb, ub
  For x=1 To numpages
    lb = (x-1) * pagesize + 1
    ub = x * pagesize
    If ub > numrecs Then ub = numrecs
    If x <> mypage Then
      Response.Write("<A HREF=category.asp?cat=cc&page=" & x & "&recs=" & pagesize & ">" & lb &

"-" & ub & "</A>")
      Response.Write(lb & "-" & ub)
    End If
    If x <> numpages Then Response.Write(" | ")


  ' Clean up
if rs.eof then
  Set rs = Nothing
  Set conn = Nothing
end if

<%end if%>




Pl. help me out...

thanks in advance.


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.06
Copyright ©2001-2023 Web Wiz Ltd.

Become a Fan on Facebook Follow us on Twitter Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2023 Web Wiz Ltd. All rights reserved.