|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
asp table formatting
<i><b>Originally posted by : Paul (paul.carey@hmv.co.uk)</b></i><br /><br /> I have a table consisting of 5 columns and 'x' records in an access database. I have connected and can display the records with headers with the following code:<br /><br />set rs = Server.CreateObject("ADODB.recordset")<br />sql="SELECT * FROM WebFinErr"<br />rs.Open sql, conn<br />%><br /><br /><table border="0" width="100%"><br /><tr><br /><%for each x in rs.Fields<br /> response.write("<th>" & x.name & "</th>")<br />next%><br /></tr><br /><%do until rs.EOF%><br /> <tr><br /> <%for each x in rs.Fields%><br /> <td><%Response.Write(x.value)%></td><br /> <%next<br /> rs.MoveNext%><br /> </tr><br /><%loop<br />rs.close<br />conn.close<br />%><br /><br />I want the 5th column record with it's header to display below the first 4 column records and headers then to loop through the table displaying similarly. An example is as below:<br /><br />col1header col2header col3header col4header<br />col1record col2record col3record col4record<br />col5header<br />col5record<br />col1header col2header col3header col4header<br />col1record col2record col3record col4record<br />col5header<br />col5record<br />col1header col2header col3header col4header<br />col1record col2record col3record col4record<br />col5header<br />col5record<br />and so on.....<br /><br />Any help from anyone would make a friend for life!!<br />
|
|
#2
|
|||
|
|||
|
<i><b>Originally posted by : B. Prasad Reddy (b_prasadreddy@yahoo.com)</b></i><br />Dear friend,<br /><br /> As far I know, this is the solution for formatting the table just it needs a small conditions inside. Read this code below and see if this suits you.<br /><br /><%@language=vbscript%><br /><!-- #include virtual="adovbs.inc" --><br /><%<br /> dim rstest,contest,i,fld<br /> <br /> set contest=Server.CreateObject("ADODB.Connection")<br /> contest.Open"Provider=sqloledb;Server=(local);Database=pubs;uid =sa;pwd="<br /> set rstest=Server.CreateObject("ADODB.Recordset")<br /> 'set rstest=contest.Execute("select * from stores")<br /> rstest.Open "select * from stores",contest,adOpenStatic<br />if not rstest.EOF then<br /><br /> Response.write"<table cellpadding=1 cellspacing=1><tr bgcolor=orange>"<br /> 'set the column header expect for the last field in the table<br /> for j=0 to rstest.Fields.Count - 2<br /> Response.write"<th>" & rstest.fields(j).Name & "</th>"<br /> next<br /> Response.write"</tr>"<br /> do while not rstest.EOF<br /> Response.write"<tr bgcolor=cyan>"<br /> for each fld in rstest.Fields<br /> 'Check whether the the field name is not equal to the last field in the table<br /> if fld.Name<> rstest(rstest.fields.Count-1).Name then<br /> Response.write"<td>" &fld.Value & "</td>"<br /> else<br /> Response.write"</tr><tr bgcolor=cyan>"<br /> 'create blank cell for all the cells in the table except for last cell 'for inserting last field name<br /> for j=0 to rstest.Fields.Count-3<br /> Response.write "<th> </th>"<br /> next<br /> Response.write"<th>" & fld.Name &"</th></tr><tr bgcolor=cyan>"<br /> 'Now similarly create blank cells for all the cells except for the last <br /> 'cell which contains last field value<br /> for j=0 to rstest.Fields.Count-3<br /> Response.write "<td> </td>"<br /> next<br /> Response.write"<td>" & fld.Value & "</td>"<br /> 'Don't close the row here as it is the last field it will be closed at 'the end of the for loop<br /> end if<br /> next<br /> Response.write "</tr>"<br /> rstest.MoveNext<br /> loop<br /> 'Close the table here<br /> 'Close the recordset and connection object<br /> Response.write "</table>"<br /> End iF<br /> rstest.Close<br /> set rstest=nothing<br /> contest.Close<br /> set contest=nothing<br /> %>
|
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > asp table formatting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|