<% '以下定义一个显示表格的函数TABDISP(),参数TAB,被显示的表名,DISPFILD,要显示的字段,FINDFILD,查询字段,PAGEN,每页显示数量,fh,显示的方向 '如显示成功,返回值为真,不成功,返回值为假. '多个字段间用,分隔 '查询字段一定要包含在显示字段中. '如字段名与要显示的名称不一样,用<分隔,前面是字段名,后面是显示的名字,而要进行搜索的字段则一定要用<分隔要字段名和显示字符 'FH显示方向为"H"时作横向显示,为"S"时作纵向显示 区分大小写 FUNCTION TABDISP(TAB,DISPFILD,FINDFILD,PAGEN,FH) On Error Resume Next IF DISPFILD="" THEN DISPFILD="*" IF PAGEN="" THEN PAGEN=15 DISPFILD1=DISPFILD&"," findfild1=findfild&","
dim findl(10),findr(10) i1=1 do while instr(findfild1,",")<>0 star=instr(findfild1,",") findl(i1)=left(findfild1,star-1) findr(i1)=findl(i1) fildbak=findl(i1) findl(i1)=left(fildbak,instr(fildbak,"<")-1) findr(i1)=right(fildbak,len(fildbak)-instr(fildbak,"<")) findfild1=right(findfild1,len(findfild1)-star) i1=i1+1 loop
Response.Write "<table border='0' width='100%' cellspacing='0'><tr><form method='GET'>" Response.Write "<TD > " 'width='50%' IF session("FLMENULBUP")<>"" THEN Response.Write "当前栏目:<A HREF='FLMEN.asp?MENULB="&SESSION("FLMENULBUP")&"'>"&MID(SESSION("FLMENULBUP"),4,200)&"</A>" END IF IF SESSION("flmenulb")<> SESSION("FLMENULBUP") THEN Response.Write " >> <A HREF='FLMEN.ASP?menulb="&SESSION("FLMENULBUP")&"&LB="&SESSION("flmenulb")&"'>"&MID(SESSION("flmenulb"),4,200)&"</A>" END IF Response.Write "</TD><td align='right' ></td><td align='right'><table border='0' cellspacing='0' cellpadding='0'> " Response.Write "<tr><td rowspan='2'><img src='img/SEARCH.GIF' width='50'> </td>" for i3=1 to i1-1 Response.Write "<td>"&findr(i3)&":</td>" next Response.Write "</tr><tr>" '<td></td> for i2=1 to i1-1 Response.Write "<td><input type='text' name='key_Word"&i2&"' size='8' value=''></td>" next
Response.Write "<tr></table></td><td width='20%'> <input type='checkbox' name='find_fr' value='yes'>精确 <input type='submit' value='开始' name='B_FIND'></td>" Response.Write "</form> </tr></table>" find_fr=request("find_fr") TJ="" urllr="&find_fr="&find_fr findlrdisp="" FOR I3=1 TO I1-1 TJ1=request("KEY_WORD"&I3) urllr=urllr&"&key_word"&i3&"="&tj1 IF TJ1=FINDR(I3) OR TJ1="" THEN TJ1="" ELSE if find_fr<>"yes" then findlrdisp=findlrdisp&findr(i3)&"包含“"&TJ1&"” " tj1=" AND "&findL(I3)&" like '%"&TRIM(TJ1)&"%' " else findlrdisp=findlrdisp&findr(i3)&"是“"&TJ1&"” " tj1=" AND "&FINDL(I3)&" = '"&TRIM(TJ1)&"' " end if END IF TJ=TJ&TJ1 IF TJ="" THEN TOPSN=" TOP 300 " ELSE TOPSN="" END IF NEXT
dim fild(35),dispfil(35),dispfildlr dispfildlr="" i=1 dispfild1=dispfild1 do while instr(dispfild1,",")<>0 star=instr(dispfild1,",") fild(i)=left(dispfild1,star-1) dispfil(i)=fild(i) if instr(fild(i),"<")<>0 then fildbak=fild(i) fild(i)=left(fildbak,instr(fildbak,"<")-1) dispfil(i)=right(fildbak,len(fildbak)-instr(fildbak,"<")) end if dispfildlr=dispfildlr&fild(i)&"," dispfild1=right(dispfild1,len(dispfild1)-star) i=i+1 loop dispfildlr=left(dispfildlr,len(dispfildlr)-1) SQL="SELECT "&topsn&" id,"&DISPFILDlr&" FROM "&TAB&" WHERE ID<>-1 "&tj&" order by -ID" 'Response.Write sql session("tabsql")=sql Set rs=Server.CreateObject("ADODB.RecordSet") rs.Open sql,conn,1,3 if not rs.eof then pagesn=request("pagesn") if pagesn<=0 or pagesn="" then pagesn=1 rs.pagesize=pagen pagezs=rs.pagecount IF cint(PAGESN)>pagezs THEN pagesn=PAGEZS zs=rs.recordcount page=(pagesn-1)*pagen rs.move page,1 if findlrdisp<>"" then Response.Write "经搜索,"&findlrdisp&"的记录如下:" Response.Write "<table border='0' width='90%'>" if zs>=300 and topsn<>"" then Response.Write "<tr> <form method='POST' action='?"&urllr&"'><td width='54%'>总数很多,当前显示前"&ZS&"条,分"&PAGEZS&"页,现在是第"&PAGESN&"页</td>" else Response.Write "<tr> <form method='POST' action='?"&urllr&"'><td width='54%'>一共"&ZS&"条,分"&PAGEZS&"页,现在是第"&PAGESN&"页</td>" end if Response.Write "<td width='11%' align='center'><a href='?PAGESN="&PAGESN-1&urllr&"'>上一页</A></td>" Response.Write "<td width='11%' align='center'><a href='?PAGESN="&PAGESN+1&urllr&"'>下一页</A></td>" Response.Write "<td width='24%' ALIGN='RIGHT'>跳转到第 " Response.Write "<input type='text' name='PAGESN' size='2'>页<input type='submit' value='GO' name='B1'></td></form> " Response.Write "</tr></table> " if fh="H" THEN Response.Write " <table border='0' width='100%' cellspacing='1' cellpadding='0'>" Response.Write " <tr bgcolor='#EDBAA5' align='center'> " for ii=1 to i-1 Response.Write "<td>"&dispFIL(ii)&"</td>" next Response.Write "</tr>" for iii=1 to pagen Response.Write "<tr bgcolor='#FFFAEE'>" FOR II=1 TO I-1 Response.Write "<td>"&RS(fild(II))&"</td>" NEXT Response.Write "</tr>" RS.MOVENEXT if rs.eof then exit for next Response.Write "</table>" ELSE Response.Write " <table border='0' width='100%' cellspacing='1' cellpadding='0'>" for iii=1 to pagen FOR II=1 TO I-1 Response.Write "<tr><td bgcolor='#EDBAA5' ALIGN='RIGHT' WIDTH='20%'>"&dispFIL(ii)&":</td><td bgcolor='#FFFAEE'>"&RS(fild(II))&"</td></tr>" NEXT Response.Write "<tr height='1'><td bgcolor='#CFBA9E' colspan='2' ALIGN='RIGHT' WIDTH='20%'> </td></tr>" RS.MOVENEXT if rs.eof then exit for next Response.Write "</table>" END IF rs.close Response.Write "<table border='0' width='90%'>" if zs>=300 and topsn<>"" then Response.Write "<tr> <form method='POST' action='?"&urllr&"'><td width='54%'>总数很多,当前显示前"&ZS&"条,分"&PAGEZS&"页,现在是第"&PAGESN&"页</td>" else Response.Write "<tr> <form method='POST' action='?"&urllr&"'><td width='54%'>一共"&ZS&"条,分"&PAGEZS&"页,现在是第"&PAGESN&"页</td>" end if Response.Write "<td width='11%' align='center'><a href='?PAGESN="&PAGESN-1&urllr&"'>上一页</A></td>" Response.Write "<td width='11%' align='center'><a href='?PAGESN="&PAGESN+1&urllr&"'>下一页</A></td>" Response.Write "<td width='24%' ALIGN='RIGHT'>跳转到第 " Response.Write "<input type='text' name='PAGESN' size='2'>页<input type='submit' value='GO' name='B1'></td></form> " Response.Write "</tr></table> " else Response.Write "没有找到合适的记录" end if if er() then tabdisp=False else tabdisp=True end if END FUNCTION
Function Er() '错误处理函数 If Err.Number = 0 Then Er = False Else Err.Clear Er = True End If End Function %>
终于看完函数了.... 各位有点累,其实仔不仔细看都没有关系.反正只管调它就是了.下面举一个应用的例子. 首先, 我们把前面的函数就是<%和%>之间的部分保存到一个叫 TABDISP.ASP的文件中. 代码如下: 显示一个职式名册表,表名: ZG 有ID 姓名 职务 职称 TEL BP DZ(地址)几个字段.