当前位置: 首页 > 图文教程 > 网络编程 > ASP > 一个功能完善的专栏管理的程序->这是asp.net的第二个应用(二)

ASP
简单ASP论坛DIY
如何防止页面中的敏感信息被提取
asp创建对象及中文显示解决技巧
基础开发入门级:JSP与ASP的比较
数据库受到限制怎么办?
ASP初学者常犯的几个错误
Asp定时执行操作、Asp定时读取数据库(网页定时操作详解)
ASP优化:非常实用的ASP提速技巧五则
ASP教程:解决ASP脚本运行超时的方法
ASP安全:简单学习ASP连接数据库方法
简单一招用ASP实现对IE地址栏参数的判断
asp控制xml数据库的6段非常的经典代码
ASP进阶:验证身份证号是否正确的代码
ASP教程:使用ASP生成图片彩色校验码
ASP进阶:用ASP判断文件地址是否有效
ASP进阶:用asp做的简单搜索引擎代码
ASP实例 挂QQ的网页源代码ASP/PHP
ASP答疑 解决ASP脚本运行超时的方法
轻轻松松破解开别人ASP木马密码的方法
用ASP操作Access数据库 ADOX的使用

ASP 中的 一个功能完善的专栏管理的程序->这是asp.net的第二个应用(二)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 40 ::
收藏到网摘: n/a

  一个功能完善的专栏管理的程序->这是asp.net的第二个应用(二)
/*
豆腐制作,都是精品
http://www.asp888.net 豆腐技术站
如转载,请保留完整版权信息
*/
我们在上篇文章中,引用了一个函数包文件func.aspx,在这篇文章中,我们详细讲解一下,这个func.aspx 文件
<%@ Assembly Name="System.Net" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
'这些import 我就不说了,在前面的的文章 sp+中常用的NameSpace的讲解都已经有所涉及
<script language="VB" runat=server>
function replaceSql(str1 as string) as string
'在asp.net 中使用SQL 语句也会出现"'"号的问题,因此使用replace函数将"'" 转换成 "''"
replaceSql=replace(str1,"'","''")
end function
function GetConn() as SQLConnection
'我们在这里 将连接数据库的代码进行统一化管理
Dim conn As SQLConnection
Dim Cfg as HashTable
Cfg = Context.GetConfig("appsettings")
Conn = New SQLConnection(cfg("Conn"))
GetConn=Conn
end function

sub WritePage(start as integer,file as string,intLen as integer,intPageCount as integer,intRecCount as integer)
'这个是一个 可移植 的 分页的程序
'进行分页处理
dim strWrite as string
strWrite="<table border=1 width=100%><tr><td>"
response.write(strWrite)

if start=0 then
strWrite="首页"
else
strWrite="<a href='" & file & "?start=0'>首页</a>"
end if
response.write(strWrite)

if start>=1 then
strWrite="<a href='" & file & "?start=" & cStr(start-intLen) & "'>上页</a>"
else
strWrite="上页"
end if
response.write(strWrite)

if start+intLen<intRecCount then
'还没有到最后一页数据
strWrite="<a href='" & file & "?start=" & cStr(start+intLen) & "'>下页</a>"
else
strWrite="下页"
end if
response.write(strWrite)

if start+intLen<intRecCount then
'还没有到最后一页数据
strWrite="<a href='" & file & "?start=" & cStr((intPageCount-1)*intLen) & "'>末页</a>"
else
strWrite="末页"
end if
response.write(strWrite & "</td><td>")

strWrite="当前共有文章" & Cstr(intRecCount) & "篇,现在是第<font color=red>" & cStr((Start/intLen)+1) & "/" & cstr(intPageCount) & "</font>页"
response.write(strWrite)
strWrite="</td></tr></table>"
response.write(strWrite)
end sub
</script>
大家在asp.net 中一定要注意,我们在asp.net 中定义函数的时候,一定要注意必须在<script runat=server ..>中对函数进行定义,而不能和asp一样在 <%和%>之间定义,这样做的好处是 对函数定义简单明了,程序的可读性提高了很多,但是有一个很不方便的地方就是 在<script>..中不能象在<%%> 中那样方便的嵌套调用HTML代码,而必须使用Response.Write(ss),这个是一个不方便的地方