Entry
How can i resize the iframe according to the field fetched from table using ASP?
Nov 14th, 2001 07:05
Peter Ritchie, Sumegha,
I'll assume you're accessing a SQL Server database (the creation and
initialization of the ADODB.Connection object isn't at issue) and
suggest the following sample code that essentially has a container page
(frContainer.asp) with an iFrame element within it, linking to
frDetail.asp.
frDetail takes one parameter named q which is the SQL statement to
execute. My example simply makes use of the spt_datatype_info table in
the master database. frContainer.asp simply assigns a SQL statement to
a variable, counts the number of rows in that recordset and creates a
IFRAME tag with an appropriate height.
Modifying line 17 of frContainer.asp modifies the query, which will,
hopefully, modify the number of rows retrieved. line 32 of
frContainer.asp creates the iFrame element tag setting the HEIGHT
attribute to a value based on the number of rows in the result set.
frDetail.asp simply executes the query and displays the results in a
table.
There are, of course, many other ways of doing this sort of thing.
This is the simplest method, not requiring the creation of other
objects:
frContainer.asp:
<%@ Language=VBScript %>
<%
Option Explicit
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<TITLE>IFRAME Test</TITLE>
<%
dim Conn, RS
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "SQLOLEDB"
Conn.Open "Server=localhost;database=master;uid=sa;Network=DBMSSOCN"
If Conn.State = 1 Then
dim sQuery
sQuery = "SELECT fixlen, TYPE_NAME, LOCAL_TYPE_NAME FROM
spt_datatype_info WHERE fixlen in(1)"
Set RS = Conn.Execute(sQuery)
Dim nRowCount
nRowCount = 0
if Not RS.EOF Then
while Not RS.EOF
nRowCount = nRowCount + 1
RS.MoveNext
wend
End if
End If
%>
</HEAD>
<BODY>
We're expecting <%=nRowcount%> Rows:<br/>
<IFRAME ID="myIFrame" WIDTH="640" HEIGHT="<%=(nRowCount)*22+75%>"
src="frDetail.asp?q=<%=sQuery%>"></IFRAME>
<script language="javascript">
myIFrame.offsetHeight=<%=nRowCount%> * 30;
</script>
</BODY>
</HTML>
frDetail.asp:
<%@ Language=VBScript %>
<%
Option Explicit
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<TITLE>IFRAME Test</TITLE>
</HEAD>
<BODY>
<%
if Len(Request.QueryString("q")) Then
dim Conn, RS
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "SQLOLEDB"
Conn.Open "Server=localhost;database=master;uid=sa;Network=DBMSS
OCN"
Set RS = Conn.Execute(Request.QueryString("q"))
if Not RS.EOF Then
Response.write "<table>" & vbCrlf
Dim field
Response.write "<tr>" & vbCrlf
for each field in RS.Fields
Response.write "<TH>" & field.name & "</TH>"
next
Response.write "</tr>" & vbCrlf
while Not RS.EOF
Response.write "<TR>"
for each field in RS.Fields
response.write "<TD>" & field & "</TD>"
& vbCrlf
Next
Response.write "</TR>"
RS.MoveNext
wend
Response.write vbCrlf & "</table>" & vbCrlf
End if
Else
%>No query specified<br/><%
End If
%>
</BODY>
</HTML>