Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2006, 07:26 AM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default add scrollbar to table

Hi, the following page is opened within an <iframe> can anybody see how it is possible to add a scrollbar ideally to just the table or to the entire window, please note <style="overflow:scroll"> isn't working within any of the tabs, i think it is because the table is populated after the page is loaded and the scrollbar function is established during the onload event?????

heres the code, thank you....

<%
    ' Declare variables
    Dim strURL ' The URL of this page so the form will work no matter what this file is named.

Dim cnnSearch ' ADO connection
Dim rstSearch ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file

Dim strSQL ' The SQL Query we build on the fly
Dim strSearch ' The text being looked for

' Retreive the URL of this page from Server Variables
strURL = Request.ServerVariables("URL")

' Retreive the term being searched for. I'm doing it on
' the QS since that allows people to bookmark results.
' You could just as easily have used the form collection.
strSearch = Request.QueryString("search")
'strSearch = Replace(strSearch, "'", "''")

%>

<h2>Internal Contact Search</h2>

<form action="<%= strURL %>" method="get">
<input name="search" value="<%= strSearch %>" />
<input type="submit" value="Search" />
</form>


<%
If strSearch <> "" Then
    ' MapPath of virtual database file path to a physical path.
    ' If you want you could hard code a physical path here.
        strDBPath = Server.MapPath("Contacts.mdb")


        ' Create an ADO Connection to connect to the sample database using OLE DB.
        cnnSearch = Server.CreateObject("ADODB.Connection")

    ' This line is for the Access sample database:
        cnnSearch.Open("Provider=Microsoft.Jet.OLEDB.4.0;D ata Source=" & strDBPath & ";")

        ' Build our query based on the input.
        strSQL = "SELECT * " _
         & "FROM [tblEmployee] " _
         & "WHERE Name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
         & "ORDER BY Name;"

        ' Execute our query using the connection object. It automatically
        ' creates and returns a recordset which we store in our variable.
        rstSearch = cnnSearch.Execute(strSQL)

        ' Display a table of the data in the recordset. We loop through the
        ' recordset displaying the fields from the table and using MoveNext
        ' to increment to the next record.
%>



<table border="0" cellspacing="2" Width="845px">
    <tr style="background-color:#5D7B9D; color:White">
    <th style="height: 16px">Name</th>
    <th style="height: 16px">Department</th>
    <th style="height: 16px">Extension</th>
    <th style="height: 16px">E-mail</th>
    </tr>


    <%
    Do While Not rstSearch.EOF
        %>
        <tr style="background-color:#F7F6F3; color:#284775;">

        <td><%= rstSearch.Fields("Name").Value %> </td>
        <td><%=rstSearch.Fields("Department").Value%></td>
        <td><%=rstSearch.Fields("Extension").Value%></td>
        <td><%=rstSearch.Fields("E-mail").Value%></td>

        </tr>
        <%

        rstSearch.MoveNext
    Loop
    %>

</table>

    <%
    ' Close our recordset and connection and dispose of the objects
    rstSearch.Close
        rstSearch = Nothing
    cnnSearch.Close
        cnnSearch = Nothing
End If
%>


</body>

 
Old May 18th, 2006, 11:29 AM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try using css "auto" in a stylesheet and it looks like your code needs a lil tlc...(for one...you have NO code checking for eof(if you don't have a rec in db wht do you suppose is going to happen?))please throw this code snippet in its own .asp page and open up...

Quick notes...by default you do not need to put fields and value...save yourself some typing...try to stray away from inline styles...use in header and even better an external .css...perhaps you need only the first few chars of the name...right now i had hardcoded an h for the search and ANY name with an h in it will be found...if not try removing the first % in sql...an sql injection is open on the search textbox...you commented out the code to somewhat protect it...it's assumed you did this beacause you are holding the value and the code you have will show 2 '' in the value...so simply replace the second string in replace function w/ #39;...code should be
 strSearch = Replace(Request.QueryString("search"),"'","#39;")


any ??...please ask...good luck

<html>
<head>
 <style>
   div.scroll {width:100%;
               height:100px;
               overflow:auto;
              }
   th {background:#5D7B9D;
       color:white;}
 </style>
</head>
<body>

<%
  sSearch = "H"
  If sSearch <> "" Then
   Set oRs = Server.CreateObject("ADODB.Recordset")
   Set oConn = Server.CreateObject("ADODB.Connection")
   sPath = Server.MapPath("Contacts.mdb")

   sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath & ";"
   oConn.Open sConn

   Set oRs = oConn.Execute("SELECT * " & _
                           "FROM [tblEmployee] " & _
                           "WHERE Name LIKE '%" & Replace(strSearch, "'", "''") & "%' " & _
                           "ORDER BY Name;")
%>

<div class="scroll">
 <table border="0" cellspacing="2" Width="100%">
  <tr>
   <th>Name</th>
   <th>Department</th>
   <th>Extension</th>
   <th>E-mail</th>
  </tr>

<%
  sColor = "#eeeeee"
  Do While Not oRs.EOF
%>

  <tr bgColor="<%=sColor%>">
   <td><%=oRs("Name")%></td>
   <td><%=oRs("Department")%></td>
   <td><%=oRs("Extension")%></td>
   <td><%=oRs("E-Mail")%></td>
  </tr>

<%
  If sColor = "#eeeeee" Then
   sColor = "#F7F6F3"
  Else
   sColor = "#eeeeee"
  End If
  oRs.MoveNext
  Loop
%>

</table>

<%
  oRs.Close
  Set oRs = Nothing
  oConn.Close
  Set oConn = Nothing

  End If
%>

   </table>
  </div>
 </body>
</html>







 
Old May 18th, 2006, 11:31 AM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ooops forgot to add the if condion in case no records were found

<html>
<head>
 <style>
   div.scroll {width:100%;
               height:100px;
               overflow:auto;
              }
   th {background:#5D7B9D;
       color:white;}
 </style>
</head>
<body>

<%
  sSearch = "H"
  If sSearch <> "" Then
   Set oRs = Server.CreateObject("ADODB.Recordset")
   Set oConn = Server.CreateObject("ADODB.Connection")
   sPath = Server.MapPath("Contacts.mdb")

   sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath & ";"
   oConn.Open sConn

   Set oRs = oConn.Execute("SELECT * " & _
                           "FROM [tblEmployee] " & _
                           "WHERE Name LIKE '%" & Replace(strSearch, "'", "''") & "%' " & _
                           "ORDER BY Name;")


%>

<div class="scroll">

<%
  If oRs.EOF Then
   Response.Write "No Records"
  Else
%>

 <table border="0" cellspacing="2" Width="100%">
  <tr>
   <th>Name</th>
   <th>Department</th>
   <th>Extension</th>
   <th>E-mail</th>
  </tr>

<%
  sColor = "#eeeeee"
  Do While Not oRs.EOF
%>

  <tr bgColor="<%=sColor%>">
   <td><%=oRs("Name")%></td>
   <td><%=oRs("Department")%></td>
   <td><%=oRs("Extension")%></td>
   <td><%=oRs("E-Mail")%></td>
  </tr>

<%
  If sColor = "#eeeeee" Then
   sColor = "#F7F6F3"
  Else
   sColor = "#eeeeee"
  End If
  oRs.MoveNext
  Loop
%>

</table>

<%
  oRs.Close
  Set oRs = Nothing
  oConn.Close
  Set oConn = Nothing

  End If
  End If
%>

   </table>
  </div>
 </body>
</html>

 
Old May 18th, 2006, 11:36 AM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

man i hate forums w/o edit...sorry all...i am not sure if forum strips it out or i missed it so spelled out and code again here...

strSearch = Replace(Request.QueryString("search"),"'","ampersa ndnumericsign39semicolon")

strSearch = Replace(Request.QueryString("search"),"'","#39;")







Similar Threads
Thread Thread Starter Forum Replies Last Post
Can someone tell me how to add a scrollbar to.... Sickopuppie HTML Code Clinic 7 June 15th, 2006 03:22 PM
Trying to center a table with scrollbar Sickopuppie HTML Code Clinic 5 June 15th, 2006 02:43 AM
problem with scrollbar and a table header touyets CSS Cascading Style Sheets 2 August 29th, 2005 12:18 AM
Scrollbar in "Table" mcinar HTML Code Clinic 10 January 16th, 2005 08:47 PM
Scrollbar in "Table" mcinar Classic ASP Basics 7 January 2nd, 2005 09:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.