Domanda

Hello and thank you for your help,

I have an .asp page where I have a repeat region that lists down the most recent entries and I have a submit button off on the side with a drop down menu where they can filter the entries by date once clicked. But, I am unsure exactly how to filter these entries. A Date is passed in mm/dd/yyyy format for that specific entry. What would the value for the dropdown menu look like? My code is listed below:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/TTTCon.asp" -->
<%
Dim rsCall
Dim rsCall_cmd
Dim rsCall_numRows

Set rsCall_cmd = Server.CreateObject ("ADODB.Command")
rsCall_cmd.ActiveConnection = MM_TTTCon_STRING
rsCall_cmd.CommandText = "SELECT * FROM tttCalls ORDER BY theDate ASC" 
rsCall_cmd.Prepared = true

Set rsCall = rsCall_cmd.Execute
rsCall_numRows = 0
%>
<%
Dim rsDate
Dim rsDate_cmd
Dim rsDate_numRows

Set rsDate_cmd = Server.CreateObject ("ADODB.Command")
rsDate_cmd.ActiveConnection = MM_TTTCon_STRING
rsDate_cmd.CommandText = "SELECT * FROM tttCalls ORDER BY monthNum ASC" 
rsDate_cmd.Prepared = true

Set rsDate = rsDate_cmd.Execute
rsDate_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
rsCall_numRows = rsCall_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Quality Call Library</title>
<link href="css/NewStyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function hideM() {
document.getElementById("Connect").style.visibility = "hidden"; 
document.getElementById("Customize").style.visibility = "hidden";   
document.getElementById("Close").style.visibility = "hidden";   
document.getElementById("Collections").style.visibility = "hidden"; 
document.getElementById("submit").style.visibility = "hidden";

}
function section1() {
document.getElementById("Connect").style.visibility = "hidden"; 
document.getElementById("Customize").style.visibility = "hidden";   
var step1Value = document.getElementById("Step1").value;
var step2Value = document.getElementById("Step2").value;
//document.getElementById("submit").style.visibility = "visible";
//alert(step1Value+" // "+step2Value);

if (step1Value == "Collections") {
    step2Value = "Collections";
    document.getElementById(step2Value).style.visibility = "visible";
    } else if(step2Value == "Connect"){
        document.getElementById("Connect").style.visibility = "visible";        
        document.getElementById("Customize").style.visibility = "hidden";   
    } 

}

</script>
</head>
<body onload="hideM()">
<center>
  <div class="ContentBackgnd"> <!-- Main Div Start -->

    <table width="950" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="12%" align="center" valign="top" class="Titles">Select Month:</td>
    <td rowspan="5" background="img/spacer_H240.png" width="1%">&nbsp;</td>
    <td colspan="3" rowspan="7" align="left" valign="top">
    <span class="Titles">Last 30 Loaded Calls</span><br />

<div id="BodyTbl">
  <% 
While ((Repeat1__numRows <> 0) AND (NOT rsCall.EOF)) 
%>
  <table width="100%" border="0" cellspacing="6" cellpadding="0" bgcolor="#CCCCCC">
    <!-- 
begin repeate
-->
    <tr>
      <td width="28%"><strong>Call Title:</strong>&nbsp; <%=(rsCall.Fields.Item("title").Value)%></td>
      <td colspan="4"><strong>Call Date:</strong>&nbsp;<%=(rsCall.Fields.Item("theDate").Value)%></td>
      </tr>
    <tr>
      <td colspan="5"><!-- <strong>Date Loaded:</strong>&nbsp;<%'=(rsLast10.Fields.Item("DateLoaded").Value)%>--></td>
      <td><strong>Listen Now:</strong>&nbsp;&nbsp;<a href="popup.asp?ID="><img src="img/Status-audio-volume-high-icon.png" width="16" height="16" border="0" /></a></td>
      </tr>
    <tr>
      <td colspan="6"><strong>Description:</strong> <%=(rsCall.Fields.Item("comments").Value)%><br /></td>
      </tr>
    <tr>
      <td colspan="6"><hr /></td>
      </tr>
    <!--end asp repeat-->
    <tr>
      <td>&nbsp;</td>
      <td width="1%">&nbsp;</td>
      <td width="8%">&nbsp;</td>
      <td width="20%">&nbsp;</td>
      <td width="3%">&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
  </table>
  <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rsCall.MoveNext()
Wend
%>
</div>

</td>
    </tr>
  <tr>
    <td align="center" valign="top"><img src="img/gryarrw.png" width="108" height="15" /></td>
    </tr>
  <tr>
    <td align="center" valign="top">
      <form id="NewForm" name="NewForm" method="get" action="Files.asp">
        <p>
          <select id="Step1" name="Step1" onchange="section1()">
            <option value="1" selected="selected">January</option>
            <option value="2">February</option>
            <option value="3">March</option>
            <option value="4">April</option>
            <option value="5">May</option>
            <option value="6">June</option>
            <option value="7">July</option>
            <option value="8">August</option>
            <option value="9">September</option>
            <option value="10">October</option>
            <option value="11">November</option>
            <option value="12">December</option>
</select>
          </p>
        <input type="submit" name="button" id="button" value="Submit" />
        </form><p></p>
    </td>
È stato utile?

Soluzione

You have following option:

Use AJAX to load/reload data upon changing month in your drop down (you call it filtering)

Just submit this form to itself, retrieve value of the month selected and pass it to select statement.

From the code provided it is unclear why do you have this part:

 <%
 Dim rsDate
 Dim rsDate_cmd
 Dim rsDate_numRows

 Set rsDate_cmd = Server.CreateObject ("ADODB.Command")
 rsDate_cmd.ActiveConnection = MM_TTTCon_STRING
 rsDate_cmd.CommandText = "SELECT * FROM tttCalls ORDER BY monthNum ASC" 
 rsDate_cmd.Prepared = true

 Set rsDate = rsDate_cmd.Execute
 rsDate_numRows = 0
 %>

since it is not in use anywhere. But if you decide to use submit option change your code as follows:

 Dim rsCall, intMonthSelected,strSQL
 Dim rsCall_cmd
 Dim rsCall_numRows
 if len(Request.Form("Step1"))>0 then 
    intMonthSelected=cInt(Request.Form("Step1"))
 else
   intMonthSelected=0
 end if
 if intMonthSelected=0 then
     strSQL="SELECT * FROM tttCalls ORDER BY theDate ASC"
 else
    strSQL="SELECT * FROM tttCalls where  Month(theDate)=" & intMonthSelected & "  ORDER BY theDate ASC"
 end if
 Set rsCall_cmd = Server.CreateObject ("ADODB.Command")
 rsCall_cmd.ActiveConnection = MM_TTTCon_STRING
 rsCall_cmd.CommandText = strSQL 
 rsCall_cmd.Prepared = true

 Set rsCall = rsCall_cmd.Execute
 rsCall_numRows = 0
 %>

rest will be the same as what you have. After you submit page it will show records for the month(from 1 to 31 depend on the length of the month) selected in dropdown. If you need a range of dates it will be a bit more complicated.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top