[web] Fill table with content on ASP page

Started by
4 comments, last by Zul 19 years, 6 months ago
I know this is a simple question, and everyone is preparing the [google] icon, but I cant seem to find anything that I can understand on the information superhighway. I am still quite new to ASP [smile] Basically, I have a table here that I am currently updating manually with content from the DB. I am trying to figure out how I can grab the fields I need from the DB and autofill the table with the content. At the moment I can only seem to figure out how to get one line to print. Any ideas?
Advertisement
You want to do something like this:

<%set rsRequests= conSR.Execute("SELECT * FROM [Master Maintenance] WHERE Something Here")	while NOT rsRequests.EOF%><TR>	<TD align=left width=250><%= rsRequests("Title") %></TD>	<TD align=right width=100><%= rsRequests("Date") %></TD>		<TD align=right width=100><%= rsRequests("Complete") %></TD>	</TR><%	rsRequests.movenext	wend%>
Quote:Original post by jswidorski
You want to do something like this:

<CODE>
<%
set rsRequests= conSR.Execute("SELECT * FROM [Master Maintenance] WHERE Something Here")
while NOT rsRequests.EOF
%>
<TD align=left width=250><%= rsRequests("Title") %></TD>
<TD align=right width=100><%= rsRequests("Request Date") %></TD>
<TD align=right width=100><%= rsRequests("Complete Date") %></TD>
</TR>
<%
rsRequests.movenext
wend
%>
</CODE>

How do I put this in a code block?


you want [ source ] tags
oh hai
boolean, what's your db? Here's an example how to do it in SQL server with vb:

I like to build the entire table with server side code, rather than jswidorski's method, but either will work fine. So in your html you've got something like:

<body>
<form>
----stuff
<%CreateTable%> ----the place where you want your table
</form>
</body>

Then in your code behind:
Public Sub CreateTable()        Dim sHTML As String        sHTML = "<TABLE STYLE=""Z-INDEX: 102; LEFT: 0px; POSITION: relative; TOP: 0px"" CELLSPACING=""0""" _        & "CELLPADDING=""1"" WIDTH=""300"" BORDER=""1"" bordercolor=""black"">"        Dim SQLConn As New SqlConnection        SQLConn.ConnectionString = ConfigurationSettings.AppSettings("ConnString")        Try            SQLConn.Open()            Dim objDA As New SqlDataAdapter            Dim objDataReader As SqlDataReader            Dim Cmd As New SqlCommand("pGetCustomers", SQLConn)            Cmd.CommandType = CommandType.StoredProcedure            Cmd.Parameters.Add(New SqlParameter("@AppID", 1))            objDataReader = Cmd.ExecuteReader            sHTML += "<TR><TD colspan=""3"">Customer Information</TD></TR>"            While objDataReader.Read                sHTML += "<TR><TD>" & objDataReader.Item("vcName") & "</TD>"                sHTML += "<TD>" & objDataReader.Item("vcAddress") & "</TD>"                sHTML += "<TD>" & objDataReader.Item("iPhoneNumber") & "</TD></TR>"            End While            objDataReader.Close()            objDataReader = Nothing            sHTML += "</TABLE>"            Response.Write(sHTML)            Cmd.Dispose()            objDA.Dispose()        Catch ex As Exception            Throw New Exception("Error getting customer information.")        Finally            SQLConn.Dispose()        End TryEnd Sub


The ConfigurationSettings.AppSettings("ConnString") line just reads the connection string I set up in web.config (which is a nice way to do things so that you don't have to write out the whole string each time. You can use either a DataReader or DataAdapter depeding on what you want to do with the data.

Oh yeah, the Sub or Function has to be public for you to be able to call it like this.
oh hai
Zul, that looks suspiciously like .NET code [wink]
Quote:Original post by evolutional
Zul, that looks suspiciously like .NET code [wink]


You got me :P
oh hai

This topic is closed to new replies.

Advertisement