Same data is displayed multiple times. Why? - asp-classic

I have an Active Server Page, which displays Bookings of the current Day in a HTML- Table. I display informations like Roomname, Organizer, From, To and Participants.
My Problem is that if i try to get the Participants from a booking, the Participants for a specific booking is displayed in multiple booking even if it does not belong to that booking.
To illustrate my Problem:
DailyPlan
As you can see the Name of the Participants "Kashif Butt" or "adad" is displayed multiple times. But they only belongs to the Booking with the name "PASS"
What could be the Problem? I searched for hours but did not found the Problem. Hope you can help me.
My Code so far:
<%
Dim connection, recordset, sSQL, sConnString, next10, prev10, P
Dim thema, rsRaum, raum_id, KOPPELBESTUHLUNG_ID, raumname, pageCount
Dim TeilnehmerNameExtern, TeilnehmerFirmaExtern
Dim CurrentDate
CurrentDate = Now()
Dim intHour
Dim intMinute
Dim intSecond
intHour = 17
intMinute = 0
intSecond = 0
Dim Time
Time = TimeSerial(intHour, intMinute, intSecond)
Dim Timeda
Timeda = Date()
Dim ts2
ts2 = Timeda + Time
Dim DayOfWeek
DayOfWeek = weekday(CurrentDate)
If CurrentDate < ts2 Then
If DayOfWeek = Weekday(7) Then
CurrentDate = DateAdd("d",2,CurrentDate)
End If
If DayOfWeek = Weekday(1) Then
CurrentDate = DateAdd("d",1,CurrentDate)
End If
If DayOfWeek = Weekday(2) or DayOfWeek = Weekday(3) or DayOfWeek = Weekday(4) or DayOfWeek = Weekday(5) or DayOfWeek = Weekday(6) Then
CurrentDate = CurrentDate
End If
Else If CurrentDate > ts2 Then
If DayOfWeek = Weekday(7) Then
CurrentDate = DateAdd("d",2,CurrentDate)
End If
If DayOfWeek = Weekday(1) Then
CurrentDate = DateAdd("d",1,CurrentDate)
End If
If DayOfWeek = Weekday(2) or DayOfWeek = Weekday(3) or DayOfWeek = Weekday(4) or DayOfWeek = Weekday(5)Then
CurrentDate = DateAdd("d",1,CurrentDate)
End If
If DayOfWeek = Weekday(6) Then
CurrentDate = DateAdd("d",3,CurrentDate)
End If
End If
End If
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Set rsRaum = Server.CreateObject("ADODB.Recordset")
sConnString = "Driver={SQL Server}; Server=localhost; Database=fifa;"
sSQL="select distinct THEMA, ID, AGENDA, VON, BIS, PERSONENZAHL, THEMA_ENABLED from VIEW_RAUMBUCHUNG_DISPO " & _
"where von >= convert(date, getdate(), 4) " & _
" and von < convert(date, dateadd(day,1, GETDATE()), 4) " & _
" and BIS >= getdate() " & _
" and STORNO is null " & _
" order by von, bis"
Connection.Open sConnString
Recordset.open sSQL, sConnString,1,1
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta http-equiv="REFRESH" content="10"/>
<style type="text/css" media="all">
body{font-family: Arial;}
h4{font-size: 10pt;font-weight: bold;white-space: nowrap;margin-top: 0; margin-bottom: 10px;}
th{font-size: 9pt;font-weight: normal;text-align: center;white-space: nowrap;}
td{font-size: 9pt;}.content
td{border: solid 1px #dadada;}.content
th{border: solid 1px #dadada;background-image: url("tbl_header_row_bg.gif"); background-repeat: repeat-x; white-space: nowrap;}
</style>
</head>
<form name=form1>
<p align="left" style="margin-top:20px;margin-bottom:20px;font-family:'Arial';font-size:20pt; color:#000000"> Daily Plan </p>
<p align="left" style="margin-top:10px;margin-bottom:20px;font-family:'Arial';font-size:10pt; color:
font-weight:bold;color:#000000"><% =formatDateTime(CurrentDate, 1)%>
</p>
</form>
<table width="100%" class="content" cellpadding="3" cellspacing="0" border="0" style="border-collapse: collapse;">
<tr>
<th width="350" align="left">Event</th>
<th width="100" align="absmiddle">Room</th>
<th width="60" align="absmiddle">From</th>
<th width="60" align="absmiddle">To</th>
<th align="left">Equipment</th>
<th align="left">Catering</th>
<th align="left">Agenda</th>
<th align="left">Participants</th>
<th align="absmiddle">Persons</th>
</tr>
<%
'If Recordset.EoF Then
'Response.write "No records to display"
Do Until Recordset.Eof
rsRaum.open "select raum_id, KOPPELBESTUHLUNG_ID from RESERVIERUNGRAUM where buchung_id = " & Recordset("ID"), Connection
raum_id = rsRaum("raum_id")
KOPPELBESTUHLUNG_ID = rsRaum("KOPPELBESTUHLUNG_ID")
rsRaum.close
' falls Kopplung, hole ID des "Parent"-Raumes
if not isNull( KOPPELBESTUHLUNG_ID ) then
rsRaum.open "select parent_id from KOPPELN where CHILD_ID = " & raum_id, Connection
if not rsRaum.EOF then
raum_id = rsRaum("parent_id")
end if
rsRaum.close
end if
'Hole Teilnehmer
' hole Raum Details
rsRaum.open "select bezeichnung from Raum where ID = " & raum_id, Connection
raumname = rsRaum("bezeichnung")
rsRaum.close
rsRaum.open "SELECT DISTINCT NAME, FIRMA FROM TEILNEHMER WHERE buchung_id = " & Recordset("ID") & " and STATUS = 2 and DAILYPLAN = 1" , Connection
if not rsRaum.EOF then
dim new_list
new_list = ""
do while not rsRaum.eof
new_list = new_list & rsRaum("NAME") & " " & "(" & rsRaum("FIRMA") & ")" & ","
rsRaum.movenext
loop
new_list = left(new_list, len(new_list)-1)
end if
rsRaum.close
rsRaum.open "SELECT DISTINCT TRIGRAM FROM TEILNEHMER WHERE buchung_id = " & Recordset("ID") & " and STATUS = 1 and DAILYPLAN = 1" , Connection
Response.Write(rsRaum.recordcount)
if not rsRaum.EOF then
dim new_list2
new_list2 = ""
do while not rsRaum.eof
new_list2 = new_list2 & rsRaum("TRIGRAM") & ","
rsRaum.movenext
loop
new_list2 = left(new_list2, len(new_list2)-1)
end if
rsRaum.close
rsRaum.Open "SELECT distinct d.Bezeichnung, rd.Bestellmenge " & _
"FROM RESERVIERUNGDIENSTLEISTUNG rd " & _
"JOIN DIENSTLEISTUNG d ON rd.DIENSTLEISTUNG_ID = d.ID " & _
"JOIN RESERVIERUNGRAUM rr ON rd.RESERVIERUNGRAUM_ID = rr.ID " & _
"JOIN DIENSTLEISTUNGSART dlart ON d.DIENSTLEISTUNGSART_ID = dlart.ID " & _
"JOIN ABRECHNUNGSGRUPPE ab ON dlart.ABRECHNUNGSGRUPPE_ID = 3 " & _
"JOIN BUCHUNG b ON rr.BUCHUNG_ID = " & Recordset("ID"), Connection
if not rsRaum.EOF then
dim new_list3
new_list3 = ""
do while not rsRaum.eof
new_list3 = new_list3 & rsRaum("Bezeichnung") & ","
rsRaum.movenext
loop
new_list3 = left(new_list3, len(new_list3)-1)
end if
rsRaum.close
if ucase( Recordset("thema_enabled") ) = "Y" or isnull(Recordset("thema_enabled")) then
thema = Recordset("THEMA")
else
thema = ""
end if
%>
<tr "margin-bottom:100px" height="30" valign="top">
<td style="overflow:hidden;"><% =thema %></td>
<td align="center"; ><% =raumname %><br></td>
<td align="center"; ><% =FormatDateTime( Recordset("von"), 4)%></td>
<td align="center"; ><% =FormatDateTime( Recordset("bis"), 4) %></td>
<td align="center"; ><br></td>
<td align="center"; ><% =new_list3 %><br></td>
<td align="center"; ><% =Recordset("agenda") %></td>
<td ><% =new_list%><br><% =new_list2%><br></td>
<td align="center"; ><% =Recordset("personenzahl") %><br></td>
</tr>
<%
Recordset.MoveNext
Loop
'End If
Recordset.Close
Set Recordset = Nothing
Connection.Close
Set Recordset = Nothing
%>
</table>
</body>
</html>

The problem is that the values of new_list and new_list2 are not cleared in each iteration

Related

Print data in table like single row with multiple column in classic asp?

Like the date with would print in column 1 to 30, I need need employee login time and log off time in single days column ...``
I need to print data in table like single row with multiple columns in classic asp
<form name="frm_display" method="post">
Welcome: <%=Session("emp_fname")%>
<br>ID: <%=Session("emp_id")%>
<%
dim con
dim query
dim rs2
set con = Server.CreateObject("ADODB.Connection")
set rs2 = Server.CreateObject( "ADODB.RECORDSET")
con.Open "Provider=SQLOLEDB.1;Password=swtest.net;Persist Security Info=True;User ID=sa;Initial Catalog=hr;Data Source=172.16.1.208"
%>
<table align="center">
<tr>
<td>Month:
<select name="selmonth">
<%for i=1 to 12%>
<%if cint(SelectedMonth)=i then%>
<option selected value="<%=i%>">
<%=monthname(i)%>
</option>
<%else%>
<option value=< %=i%>>
<%=monthname(i)%>
</option>
<%end if%>
<%next%>
</select>
Year:
<select name="selyear">
<%for i=2000 to year(now)%>
<option select value=<%=i%>>
<%=i%>
</option>
<%next%>
</select>
<input type="Submit" value="Submit" name="btn_submit">
</td>
</tr> <!-- <-- missing! -->
</table>
</form>
<%
dim dt
dt = "1-" & monthname(Request.Form("sel_month")) & "-" & Request.Form("sel_year")
query = "select e.emp_id,e.emp_name,e.CompDepart,e.des_name,U.login_time,U.logoff_time,U.login_date " &_
"from egv_emp_departments e " &_
"inner join login_mast U on U.emp_id=e.emp_id " &_
"where month(login_date)='" & request.form("selmonth") &_
"' AND year(login_date)='" & request.form("selyear") &_
"' AND e.emp_id='" & Session( "emp_id") & "'"
rs2.open query,con
%>
<table border="1" width="100%">
<tr> <!-- added missing tr tag -->
<td>emp_id</td>
<td>emp_name</td>
<td>CompDepart</td>
<td>des_name</td>
<%
dim intDay
dim daysInMonth
dim strMonth
dim stryear
intDay=1
strMonth = request("selmonth")
stryear = request("selyear")
If strMonth <> "" Then
If stryear <> "" Then
Select Case strMonth
Case 1,3,5,7,8, 10,12 daysInMonth = 31
Case 4, 6, 9, 11 daysInMonth = 30
Case 2
if stryear mod 4 = 0 Then
If stryear mod 100 = 0 AND stryear mod 400 <> 0 Then
daysInMonth = 28
Else
daysInMonth = 29
End if
Else
daysInMonth=28
End if
End Select
Do While intDay <= daysInMonth
Response.Write "<td>" & intDay & "</td>"
intDay = intDay + 1
Loop
Else
End if
End if
for each x in rs2.fields ' <-- fixed typo "feilds"
response.write "<th>" & x.name & "<th>"
next
%>
</tr> <!-- added missing /tr tag -->
<%do until rs2.EOF %>
<tr>
<%for each x in rs2.Fields%>
<td>
<%Response.Write(x.value)%>
</td>
<% next %>
<% rs2.MoveNext %>
</tr>
<%loop
rs2.close
con.close %>
</table>
At first, I thought you wanted what's called a "PivotTable" in Excel, but then I noticed that you're filtering to a single employee. It's still not clear to me what you mean by "single days column" vs. "like single row with multiple column", but I assume you mean something like:
Employee: Smith, John
ID: 123456
Month: March
—————————————————
Day | In | Out
1 | 8 | 5
2 | 8 | 5
3 | - | -
4 | 9 | 5
... | ... | ...
30 | 9 | 4
31 | 8 | 4
—————————————————
In other words, your problem is that there might be days with no data, but you still want to print those rows. The simplest way to handle that is probably a temp table with the numbers 1 through 31 in it, which you then use in an outer join with the rest of your query. If you can't do that (e.g. you're not allowed to create temp tables - don't laugh, it happens), then you can do it in code instead.
The easiest way to do it in code is to put the values from the database into an array, but not by using GetRows. Instead, put each day's value into the corresponding row of the array.
dim listdays(31,1)
...
Do Until rs2.EOF
dt = Day(rs2("login_date"))
listdays(dt,0) = rs2("login_time")
listdays(dt,1) = rs2("logoff_time")
rs2.Movenext
Loop
(I'll pause while the purists finish having conniptions. Trust me, any performance hit from using Movenext on a recordset that contains, at most, 31 rows, is going to be so infinitesimal as to be nonexistent.)
Then you simply write out the contents of the array.
Response.Write "<table><tr><th>Day</th><th>Login</th><th>Logoff</th></tr>"
For i = 1 to DaysInMonth
Response.Write "<tr>"
Response.Write "<th>" & i & "</th>"
Response.Write "<td>" & listdays(i,0) & "</td>"
Response.Write "<td>" & listdays(i,1) & "</td>"
Response.Write "</tr>"
Next
Response.Write "</table>"

How to modify Active Server Page

I have done an Active Server Page. It is running on a foyerdisplay. The ASP is displaying meetings on that Display. I limited the displaying meetings to 10. The display can display 5-6 meeting at a time. What i want is that if the display is filled with the first 6 meetings the display should "change" to a second page which displays the last 4 meeting. That should happen every 10 seconds. 10 Seconds the first 6 meetings, 10 seconds the 4 meetings and so on. How can I do that?
My Code so far:
<table cellpadding="0" style="table-layout:fixed;width:800px;">
<tr height="15"> <td colspan="6" class="underline"></td> </tr>
<colgroup>
<col style="width:830px" >
</colgroup>
<tr><td> </td></tr>
</table>
<table cellpadding="0" border = "1" style="background-color:white; dotted black;border-collapse:collapse;table-layout:fixed;width:1270px;">
<colgroup>
<col style="width:445px" >
<col style="width:275px" >
<col style="width:125px" >
<col style="width:125px" >
<col style="width:150px" >
<col style="width:150px" >
</colgroup>
<br></br>
<tr style="background-color:blue; height="50">
<th align="left">Seminartitel</th>
<th align="left">Zusatz-Info</th>
<th align="absmiddle">von</th>
<th align="absmiddle">bis</th>
<th align="absmiddle">Gebäude</th>
<th align="absmiddle">Raum</th>
</tr>
<%
set rs=Server.CreateObject("ADODB.recordset")
set rsRaum=Server.CreateObject("ADODB.recordset")
rs.Open "select distinct buchung_id, von, bis, abteilung, veranstalter, THEMA, THEMA_ENABLED " & _
" from RESERVIERUNGRAUM r " & _
" ,BUCHUNG b " & _
" where r.BUCHUNG_ID = b.ID " & _
" and von >= convert(date, getdate(), 4) " & _
" and von < convert(date, dateadd(day,1, GETDATE()), 4) " & _
" and BIS >= getdate() " & _
" and STORNO is null " & _
" order by von, bis" _
,objConn
' Anzahl der darzustellenden Veranstaltungs-Zeilen
lineMax = 10
lineCount = 1
color = "color1"
do until rs.EOF
' Buchungen anzeigen oder nicht
rsRaum.open "select DISPLAY_ENABLED from Buchung where ID = " & rs("buchung_id"), objConn
displayanzeige = rsRaum("DISPLAY_ENABLED")
rsRaum.close
' Hole für lfd. Buchung aus erster Reservierung Raum ID und Indikator für Kopplung
rsRaum.open "select raum_id, KOPPELBESTUHLUNG_ID from RESERVIERUNGRAUM where buchung_id = " & rs("buchung_id"), objConn
raum_id = rsRaum("raum_id")
KOPPELBESTUHLUNG_ID = rsRaum("KOPPELBESTUHLUNG_ID")
rsRaum.close
'Gebäude
rsRaum.open "select distinct g.BEZEICHNUNG " & _
"from GEBAEUDE g, ETAGE e, RAUM r " & _
"Where g.ID = e.GEBAEUDE_ID and e.GEBAEUDE_ID = r.GEBAEUDE_ID and r.ID = " & raum_id, objConn
GebaeudeBezeichnung = rsRaum("BEZEICHNUNG")
rsRaum.close
'Hole Terminal Hinweistext
rsRaum.open "select KSTR from Buchung where ID = " & rs("buchung_id"), objConn
Hinweistext = rsRaum("KSTR")
rsRaum.close
' falls Kopplung, hole ID des "Parent"-Raumes
if not isNull( KOPPELBESTUHLUNG_ID ) then
rsRaum.open "select parent_id from KOPPELN where CHILD_ID = " & raum_id, objConn
if not rsRaum.EOF then
raum_id = rsRaum("parent_id")
end if
rsRaum.close
end if
' hole Raum Details
rsRaum.open "select bezeichnung from Raum where ID = " & raum_id, objConn
raumname = rsRaum("bezeichnung")
rsRaum.close
' Beende, falls Display voll
If lineCount > lineMax Then
exit do
End If
' optionale Unterdrückung der Titelanzeige
if ucase( rs("thema_enabled") ) = "Y" or isnull(rs("thema_enabled")) then
thema = rs("thema")
else
thema = ""
end if
if ucase(displayanzeige) = "Y" or isnull(displayanzeige) then
%>
<tr "margin-bottom:100px" height="70" valign="top">
<td style="overflow:hidden;" class="<% =color%>"><% =thema %></td>
<td class="<% =color%>"><% =Hinweistext %></td>
<td align="center"; class="<% =color%>"><% =FormatDateTime( rs("von"), 4)%></td>
<td align="center"; class="<% =color%>"><% =FormatDateTime( rs("bis"), 4) %></td>
<td align="center"; class="<% =color%>"><% =GebaeudeBezeichnung %><br></td>
<td align="center"; class="<% =color%>"><% =raumname %><br></td>
</tr>
<%
' jede zweite Zeile mit anderer Schriftfarbe
If lineCount mod 2 = 1 Then
color = "color2"
Else
color = "color1"
End If
lineCount = lineCount + 1
end if
rs.moveNext
loop
rs.close
%>
How can I modify my Code?
Create a duplicate page and pass a parameter (GET or POST) to it as RemainingItems from current page. RemainingItems here is 4 and change the current page as following:
If lineCount > lineMax Then
TO be:
If lineCount > firstPageItems Then
obviously:
lineMax = firstPageItems + RemainingItems
For switching between pages, in specific intervals, you should use JavaScript timer on both pages. After time elapsed, redirect the client to the other page (each page knows the address of the other).
It is possible to do all the work in one page but since it need more work, according to question I suggest this one.

Array looping order issue

Hey all i am trying to get my array in the correct format to be placed into an ASP.net webpage for a table for an order.
The order should be:
model_number
comm_category
service
freight
sales_tax
sales
unit_price
price
id_price
Currently it is outputting as this:
model_number
price
unit_price
id_price
sales_tax
sales
service
freight
comm_category
And because of this i am unable to append to my string in the correct order using my code here:
Public Sub AssocArray_To_String(ByRef Output As System.Text.StringBuilder, ByVal AssocArrayInput As AssocArray)
For iParent As Integer = 0 To AssocArrayInput.Count - 1
Dim intX As Integer = 0
Dim arrParent As AssocArray = TryCast(AssocArrayInput.Item(iParent), AssocArray)
If arrParent Is Nothing Then Continue For
For iChild As Integer = 0 To arrParent.Count - 1
Call buildItems(PHPConvert.ToString(arrParent.Keys(iChild)), PHPConvert.ToString(arrParent.Values(iChild)), intX)
intX += 1
Next iChild
Next iParent
End Sub
Private Sub buildItems(ByVal nameOfItem As String, ByVal itemItself As String, ByVal intX As Integer)
Dim tmpStuff As Decimal = 0.0
Dim qty As Integer = 1
Dim model_number As String = ""
Dim comm_category As String = ""
Dim service As Double = 0
Dim freight As Double = 0
Dim sales_tax As Double = 0
Dim sales As Double = 0
Dim unit_price As Double = 0
Dim price As Double = 0
Dim id_price As Double = 0
If nameOfItem = "model_number" Then
model_number = itemItself
tableLoop += "<tr><td bgcolor=""#CCCCCC""><asp:Label ID=""item_count_" & intX & """ Text=""Label"">" & qty & "</asp:Label></td>"
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""model_number_" & intX & """ Text=""Label"">" & model_number & "</asp:Label></td>"
ElseIf nameOfItem = "comm_category" Then
comm_category = itemItself
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""comm_category_" & intX & """ Text=""Label"">" & comm_category & "</asp:Label></td>"
ElseIf nameOfItem = "service" Then
service = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""service_" & intX & """ Text=""Label"">" & service & "</asp:Label></td>"
ElseIf nameOfItem = "freight" Then
freight = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td><asp:Label ID=""freight_" & intX & """ Text=""Label"">" & freight & "</asp:Label></td>"
ElseIf nameOfItem = "sales_tax" Then
sales_tax = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td><asp:Label ID=""sales_tax_" & intX & """ Text=""Label"">" & sales_tax & "</asp:Label></td>"
ElseIf nameOfItem = "sales" Then
sales = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""sales_" & intX & """ Text=""Label"">" & sales & "</asp:Label></td>"
ElseIf nameOfItem = "unit_price" Then
unit_price = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""unit_price_" & intX & """ Text=""Label"">" & unit_price & "</asp:Label></td></tr>"
ElseIf nameOfItem = "price" Then
price = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td><asp:Label ID=""amount_" & intX & """ Text=""Label"">" & price & "</asp:Label></td>"
ElseIf nameOfItem = "id_price" Then
id_price = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td><asp:Label ID=""id_price_" & intX & """ Text=""Label"">" & id_price & "</asp:Label></td>"
End If
End Sub
The end results are this:
<tr><td bgcolor="#CCCCCC"><asp:Label ID="item_count_0" Text="Label">1</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="model_number_0" Text="Label">TTN491-7BW</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="sales_1" Text="Label">3084.63</asp:Label></td>
<td><asp:Label ID="amount_2" Text="Label">3810</asp:Label></td>
<td><asp:Label ID="sales_tax_3" Text="Label">290.37</asp:Label></td>
<td><asp:Label ID="id_price_4" Text="Label">3810</asp:Label></td></tr>
<td bgcolor="#CCCCCC"><asp:Label ID="comm_category_5" Text="Label">X24</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="service_6" Text="Label">51</asp:Label></td>
<td><asp:Label ID="freight_7" Text="Label">384</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="unit_price_8" Text="Label">3135.63</asp:Label></td></tr>
Which should output like this:
<tr><td bgcolor="#CCCCCC"><asp:Label ID="item_count_0" Text="Label">1</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="model_number_0" Text="Label">TTN491-7BW</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="comm_category_5" Text="Label">X24</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="service_6" Text="Label">51</asp:Label></td>
<td><asp:Label ID="freight_7" Text="Label">384</asp:Label></td>
<td><asp:Label ID="sales_tax_3" Text="Label">290.37</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="sales_1" Text="Label">3084.63</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="unit_price_8" Text="Label">3135.63</asp:Label></td></tr>
<td><asp:Label ID="amount_2" Text="Label">3810</asp:Label></td>
<td><asp:Label ID="id_price_4" Text="Label">3810</asp:Label></td></tr>
How can i put the array in the correct order?
Why aren't you just simply referencing the items you need directly, instead of looping through the associative keys (which come back in arbitrary order):
Dim arrParent As AssocArray = TryCast(AssocArrayInput.Item(iParent), AssocArray)
If arrParent Is Nothing Then Continue For
Call buildItems("model_number", PHPConvert.ToString(arrParent.Values("model_number")), intX)
Call buildItems("comm_category", PHPConvert.ToString(arrParent.Values("model_number")), intX)
Call buildItems("service", PHPConvert.ToString(arrParent.Values("model_number")), intX)
Call buildItems("freight", PHPConvert.ToString(arrParent.Values("model_number")), intX)
'ETC
Or better yet, just get rid of BuildItems altogether and inline the logic in the appropriate places above.
You are calling
For iChild As Integer = 0 To arrParent.Count - 1
Call buildItems(PHPConvert.ToString(arrParent.Keys(iChild)),
PHPConvert.ToString(arrParent.Values(iChild)),
intX)
intX += 1
Next iChild
Therefor you will always get the order of the items in arrParent. So all you have to do ist call buildItems(...) manually in the correct order
Call buildItems(PHPConvert.ToString("model_number"),
PHPConvert.ToString(arrParent.Values("model_number")),
intX)
Call buildItems(PHPConvert.ToString("comm_category"),
PHPConvert.ToString(arrParent.Values("comm_category")),
intX)
' and so on
Furthermore I can't find a definition for tableLoop in buildItems. It seems that this is a simple string variable. You should make use of a StringBuilder as this class is way faster in concatenating strings! See MSDN.

Dynamically changing a table cell background color in asp.net

I have the following table row on my .aspx page:
<tr>
<td valign="bottom" style="width: 157px">Initial Requirements: </td>
<asp:Repeater ID="Repeater11" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
<td valign="bottom" id="ReqStatus" runat="server" style="background-color: Gray">
<%#ReqStatus(CType(CType(Container.DataItem, System.Data.DataRowView).Row, DataSet1.DataTable1Row))%>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
In the code behind I have this function:
Protected Function ReqStatus(ByVal Project As DataSet1.DataTable1Row) As String
'Dim ReqTableCell As TableCell
'ReqTableCell = form1.FindControl("ReqStatus")
' Check the status of the Development Completed
Dim rightNow As Date = Now()
Dim dateDifference As TimeSpan
If Not Project.IsNull("Requirements_Target") Then
Dim ReqTargetDate As Date = Project.Requirements_Target
If Project.IsNull("Req_Date") Then
dateDifference = ReqTargetDate.Subtract(rightNow)
If dateDifference.Days > 0 Then
If dateDifference.Days >= 60 Then
'ReqTableCell.BackColor = Drawing.Color.Green
Return "<strong><font color='green'>" & dateDifference.Days & "</font></strong>"
ElseIf dateDifference.Days > 30 And dateDifference.Days < 60 Then
'ReqTableCell.BackColor = Drawing.Color.Yellow
Return "<strong><font color='yellow'>" & dateDifference.Days & "</font></strong>"
Else
'ReqTableCell.BackColor = Drawing.Color.Red
Return "<strong><font color='red'>" & dateDifference.Days & "</font></strong>"
End If
Else
'ReqTableCell.BackColor = Drawing.Color.Red
Dim pastDue As Int16 = (dateDifference.Days * -1)
Return "<strong><font color='red'>" & pastDue & "</font></strong> days past"
End If
End If
Else
End If
End Function
I can change the color of the return value based on conditional statements but cannot figure out the correct syntax to change the table cell back ground. My attempt is commented out.
How do I correctly declare the table cell? Findcontrol must not be the correct way.
Look this snipping of my solution:
TableRow tr = new TableRow();
TableCell tc = new TableCell { Text = "someText"};
tc.BackColor = ColorTranslator.FromHtml("#0000FF");
tc.ForeColor = ColorTranslator.FromHtml("#FFFFFF");
tc.Font.Bold = true;
tc.Font.Size = 16;
tr.Cells.Add(tc);
table.Rows.Add(tr);
After doing this and controlling all statements you can render the table in web page.
You can do that in Codebehind with full control (untested, only to give you the idea):
Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item
Dim Project As DataSet1.DataTable1Row = DirectCast(DirectCast(e.Item.DataItem, System.Data.DataRowView).Row, DataSet1.DataTable1Row)
Dim tdReqStatus As HtmlTableCell = DirectCast(e.Item.FindControl("tdReqStatus"), HtmlTableCell)
Dim lblReqStatus As Label = DirectCast(e.Item.FindControl("lblReqStatus"), Label)
' Check the status of the Development Completed
Dim rightNow As Date = Now()
Dim dateDifference As TimeSpan
If Not Project.IsNull("Requirements_Target") Then
Dim ReqTargetDate As Date = Project.Requirements_Target
If Project.IsNull("Req_Date") Then
dateDifference = ReqTargetDate.Subtract(rightNow)
lblReqStatus.Font.Bold = True
If dateDifference.Days > 0 Then
If dateDifference.Days >= 60 Then
tdReqStatus.BgColor = "Green"
lblReqStatus.Text = dateDifference.Days.ToString
ElseIf dateDifference.Days > 30 And dateDifference.Days < 60 Then
tdReqStatus.BgColor = "Yellow"
lblReqStatus.Text = dateDifference.Days.ToString
Else
tdReqStatus.BgColor = "Red"
lblReqStatus.Text = dateDifference.Days.ToString
End If
Else
tdReqStatus.BgColor = "Red"
lblReqStatus.Text = (dateDifference.Days * -1).ToString
End If
End If
End If
End Select
End Sub
and on the aspx:
<table>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td valign="bottom" id="TdReqStatus" runat="server" >
<asp:label ID="lblReqStatus" runat="server" ></asp:label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>

How to display data in table using asp.net

Could you help to give me the sample for display data in table using asp.net.
I using this SQL query:
SELECT
pvt.CityName,
pvt.[Deluxe Class],
pvt.[Superior Class],
pvt.[Standard Class]
FROM
(SELECT
c.CityName,
h.HotelName,
tc.TourClass
FROM
tblCity2 c
LEFT JOIN
tblTourHotel2 th ON c.CityID = th.CityID
LEFT JOIN
tblHotel2 h ON th.HotelID = h.HotelID
LEFT JOIN
tblTourClass2 tc ON th.TourClassID = tc.TourClassID) t
PIVOT (
MAX(HotelName)
FOR TourClass IN ([Deluxe Class], [Superior Class], [Standard Class])
) AS pvt
and using table:
<table class="TableTour2" border="0" cellSpacing="0" cellPadding="0" width="500">
<tbody>
<tr>
<th scope=col>City</th>
<th scope=col>Deluxe Class</th>
<th scope=col>Superior Class</th>
<th scope=col>Standard Class</th>
</tr>
<%
Dim cnnPH As New System.Data.SqlClient.SqlConnection
Dim drPH As System.Data.SqlClient.SqlDataReader
Dim cmdPH As System.Data.SqlClient.SqlCommand
Try
cnnPH.ConnectionString = ConStr
cnnPH.Open()
cmdPH = New System.Data.SqlClient.SqlCommand("SELECT pvt.CityName, pvt.[Deluxe Class], pvt.[Superior Class], pvt.[Standard Class] " & _
" FROM ( SELECT " & _
" c.CityName, h.HotelName, tc.TourClass " & _
" FROM tblCity2 c " & _
" LEFT JOIN tblTourHotel2 th ON c.CityID = th.CityID " & _
" LEFT JOIN tblHotel2 h ON th.HotelID = h.HotelID " & _
" LEFT JOIN tblTourClass2 tc ON th.TourClassID = tc.TourClassID " & _
" WHERE th.TourID='1' " & _
" ) t " & _
" PIVOT ( MAX(HotelName) FOR TourClass IN ([Deluxe Class], [Superior Class], [Standard Class]) " & _
" ) AS pvt", cnnPH)
drPH = cmdPH.ExecuteReader
While drPH.Read
%>
<tr>
<th class=sub><%Response.Write(drPH("CityName"))%> </th>
<td><% Response.Write(drPH("HotelName"))%></td>
<td><% Response.Write(drPH("HotelName"))%></td>
<td><% Response.Write(drPH("HotelName"))%></td>
</tr>
<%
End While
drPH = Nothing
cnnPH.Close() : cnnPH = Nothing
Catch ex As Exception
MsgBox(ex.Message)
drPH = Nothing
cnnPH.Close() : cnnPH = Nothing
End Try
%>
</tbody>
</table>
Sorry for something wrong because I am not good with SQL and asp.net program.
I am waiting for your help
many thanks
Kosal
Don't loop like that. Keep code out of the markup. Look into using a GridView or ListView or one of the other DataBound controls.

Resources