...

View Full Version : Sort Repeated Region



urko
08-30-2005, 12:20 PM
Can any1 tell me how could I sort repeated region??
I have made repeated region to display records from DB (ID DESC ).

Now I would like that users can also sort records by name, title, ( ASC or DESC ) in browser!



<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 15
Repeat1__index = 0
loads_numRows = loads_numRows + Repeat1__numRows
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT loads.EOF))
%>
<table width="100%" border="0" cellpadding="0" height="20" cellspacing="0" style="border-bottom:1px solid #000000;border-right:1px solid #000000;border-left:1px solid #000000;" bgcolor="">
<!--DWLayoutTable-->
<tr><%If (Repeat1__numRows Mod 2) Then%>
<tr style="background-color:#FCEED6">
<%Else%>
<tr style="background-color:#ffffff">
<%End If%>
<td width="15%" valign="middle" style="padding-left:5px;"><div align="left"><a href="#" onClick="MyWindow=window.open('http://myserver/myfolder/myfolder1/loads_display.asp?load_id=<%=(loads.Fields.Item("Load_id").Value)%>','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no, width=500,height=620'); return false;"><%=(loads.Fields.Item("Load_id").Value)%></a></div></td>
<td width="30%" valign="middle" style="padding-left:5px;"><div align="left"><%=(loads.Fields.Item("bullet_weight").Value)%>&nbsp;<%=(loads.Fields.Item("bullet").Value)%></div></td>
<td width="30%" valign="middle" style="padding-left:5px;"><div align="left"><%=(loads.Fields.Item("powder").Value)%></div></td>
<td width="25%" valign="middle" style="padding-left:5px;"><div align="left"><%=(loads.Fields.Item("unit_mettric_english").Value)%> </div></td>
</tr>
</table>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
loads.MoveNext()
Wend
%>

Thanks,

neocool00
08-30-2005, 02:19 PM
Well what you can do is on your headers for the display table, turn them into links passing in a variable and then use that as the sorting mechanism.


...
<tr>
<th><a href="page.asp?sort=Name">Name</a></th>
<th><a href="page.asp?sort=Title">Title</a></th>
</tr>
...
<%
strSQL = "Select * from table"
If Request("sort") <> "" Then strSQL = strSQL & " order by " & Request("sort")
Set rs = Connection.Execute(strSQL)
%>

urko
08-30-2005, 02:42 PM
Well what you can do is on your headers for the display table, turn them into links passing in a variable and then use that as the sorting mechanism.


...
<tr>
<th><a href="page.asp?sort=Name">Name</a></th>
<th><a href="page.asp?sort=Title">Title</a></th>
</tr>
...
<%
strSQL = "Select * from table"
If Request("sort") <> "" Then strSQL = strSQL & " order by " & Request("sort")
Set rs = Connection.Execute(strSQL)
%>


Not sure if I understand you correctly.
Also, I get this error al the time:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''

Also here is my rs

<%
Dim loads__MMColParam
loads__MMColParam = "1"
If (Request.QueryString("id") <> "") Then
loads__MMColParam = Request.QueryString("id")
End If
%>
<%
Dim loads
Dim loads_numRows

Set loads = Server.CreateObject("ADODB.Recordset")
loads.ActiveConnection = MM_search_STRING
loads.Source = "SELECT * FROM [Submit_load Poizvedba] WHERE id = " + Replace(loads__MMColParam, "'", "''") + " ORDER BY Load_id DESC"
loads.CursorType = 0
loads.CursorLocation = 2
loads.LockType = 1
loads.Open()

loads_numRows = 0
%>

neocool00
08-30-2005, 04:40 PM
See changes in red. Once you make these changes, all you have to do is pass in a request called sort with a value corresponding to one of the columns in your table.

<%
Dim loads__MMColParam
loads__MMColParam = "1"
If (Request.QueryString("id") <> "") Then
loads__MMColParam = Request.QueryString("id")
End If
%>
<%
Dim loads
Dim loads_numRows
Dim strSort
If Request("sort") <> "" Then
strSort = Request("sort")
Else
strSort = "Load_id"
End If

Set loads = Server.CreateObject("ADODB.Recordset")
loads.ActiveConnection = MM_search_STRING
loads.Source = "SELECT * FROM [Submit_load Poizvedba] WHERE id = " + Replace(loads__MMColParam, "'", "''") + " ORDER BY " & strSort & " DESC"
loads.CursorType = 0
loads.CursorLocation = 2
loads.LockType = 1
loads.Open()

loads_numRows = 0
%>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum