I am creating a table directly from the ADO recordset using field.name and field.value. As seen from another prior post Retrieve ADO Recordset Field names (Classic ASP).
Taking it a step further, I am trying to rename the table headers based on values from another database. Essentially if th = Column_1
then write "First Name" etc.
I can do this individually with a "if then" function with specific code. However, I have another data base that has all the proper heading names and would rather use while loop via a recordset. Instead of writing each line - columnheading1=x and columnheading2=y etc I would rather create a while loop.
Again the single "if then" statements work fine as noted below in the code, but the recordset does not.
I have tried to fix the recordset and the loop, but no good. Any ideas why the while loop (or repeat region) would not work in the function?
Below is the example:
<table>
<thead>
<tr>
<%
Function Header_Name_Sub(Header_NameX)
Header_Name_Write = Header_NameX
If Header_Name_Write = "Project_File_ID" Then
Header_Name_Write = "File ID" ' this works great.
End If
If Header_Name_Write = "Project_Assignment_Name" Then
Header_Name_Write = "Project Name" ' this works great.
End If
' Have a data base of all header names based on column name ... this repeat is not working in the function. If I pull it out this section works fine elsewhere in the page...
Do While Not RS_Build_Numeric_Names.EOF
If CStr(Header_Name_Write) = CStr((RS_Header.Fields.Item("True_Column_Name").Value)) Then ' thought maybe string issue is why CStr
Header_Name_Write = (RS_Build_Numeric_Names.Fields.Item("Fixed_Column_Name").Value
End If
Loop
If Header_Name_Write = "Project_City" Then
Header_Name_Write = "City" ' this works great.
End If
End Function
%>
<%For Each fld in RS.Fields%>
<%
Header_Name_Sub(fld.Name)
%>
<th><span><%=Header_Name_Write%></span></th>
<%Next %>
</tr>
</thead>
<tbody>
<%
Do Until RS.EOF
OutputRow RS.Fields
RS.MoveNext
Loop
%>
</tbody>
</table>
<%
Sub OutputRow(fields)
%>
<tr>
<%For Each fld in fields%>
<td><span><%=(fld.Value)%></span></td>
<%Next %>
</tr>
<%
End Sub
%>
So here is the edit in simple form I just realized. Within the Function...
If Header_Name_Write = "Project_File_ID" Then
Header_Name_Write = "File ID" ' this works great.
End If
Works great above. I was trying to use the while loop to write the 50+ additional 'If Then's' When instead it was just looping through. So how can I write in the function the extra's?
If x = 1 Then Header_Name_Write = "File ID" End If
If x = 2 Then Header_Name_Write = "Next Header" End If
If x = 3 Then Header_Name_Write = "Another Header" End If
Is it a for loop instead?
A little further along...
For Each fld in RS_Build_Numeric_Names.Fields
If Header_Confirm = (RS_Build_Numeric_Names.Fields.Item("Build_Project_Metric_Column_Name").Value) Then
Header_Name_Write = (RS_Build_Numeric_Names.Fields.Item("Build_Project_Metric_Name").Value)
End If
Next
If I use a for statment is does work for the first record only in the recordset... not the whole loop.