Hey
I'm new to asp.net, but experienced with php.
I'm having a little trouble getting my head around this language.
I've written a script that pulls in values from a database and then loops through the results creating a positioned, styled div for each.
The problem is, the code that has been created by the script is being output above the page <html> tag and not ni the body.
Can anybody help me out and shed some light on the subject.
Cheers.
My code is here:
Code:
<%@ Import Namespace = "System.Data.SqlClient" %>
<html>
<head>
<title>Equalitree!</title>
<style type="text/css">
div {
text-align:center;
color:#fff;
}
#tree {
width:600px;
height:600px;
border:1px solid black;
background: transparent url(tree.png) no-repeat;
}
.leaf-green {
background: transparent url(leaf-green.png) no-repeat;
width:50px;
height:30px;
position:relative;
}
.leaf-red {
background: transparent url(leaf-red.png) no-repeat;
width:50px;
height:30px;
position:relative;
}
.leaf-blue {
background: transparent url(leaf-blue.png) no-repeat;
width:50px;
height:30px;
position:relative;
}
</style>
</head>
<body>
<script id="tree" language = "VB" runat ="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim ConnStr As String
ConnStr = "Data Source=STEPHEN\SQLEXPRESS; Integrated Security=SSPI;"
ConnStr = ConnStr + "Initial Catalog=tree"
Dim conn As SqlConnection = New SqlConnection(ConnStr)
conn.Open()
' Declarations
Dim MyCommand As System.Data.SqlClient.SqlCommand
Dim MyDataReader As System.Data.SqlClient.SqlDataReader
' Open the connection and execute a SQL Statement
MyCommand = New System.Data.SqlClient.SqlCommand
MyCommand.Connection = conn
MyCommand.CommandText = "SELECT id, colour, number, leftpos, toppos, info FROM leaves"
MyDataReader = MyCommand.ExecuteReader()
Response.Write("<div id=tree>")
' Loop through the DataReader and write out each entry
While MyDataReader.Read
Response.Write("<div class=leaf-" & MyDataReader.Item("colour") & " left=" & MyDataReader.Item("leftpos") & "px top=" & MyDataReader.Item("toppos") & "px>" & MyDataReader.Item("number") & "</div>")
End While
Response.Write("</div>")
' Clean Up
MyDataReader.Close()
MyDataReader = Nothing
MyCommand = Nothing
conn.Close()
ConnStr = Nothing
End Sub
</script>
</body>
</html>
Stephen
Last edited by keeps21; 10-06-2008 at 12:03 PM..
|