一个功能完善的专栏管理的程序->这是asp.net的第二个应用(二)
/*
豆腐制作,都是精品
http://www.asp888.net 豆腐技术站
如转载,请保留完整版权信息
*/
我们在上篇文章中,引用了一个函数包文件func.aspx,在这篇文章中,我们详细讲解一下,这个func.aspx 文件
1@ Assembly Name="System.Net"
1@ Import Namespace="System.Net"
1@ Import Namespace="System.IO"
1@ Import Namespace="System.Data"
1@ Import Namespace="System.Data.SQL"
'这些import 我就不说了,在前面的的文章 sp+中常用的NameSpace的讲解都已经有所涉及
1<script language="VB" runat="server">
2function replaceSql(str1 as string) as string
3'在asp.net 中使用SQL 语句也会出现"'"号的问题,因此使用replace函数将"'" 转换成 "''"
4replaceSql=replace(str1,"'","''")
5end function
6function GetConn() as SQLConnection
7'我们在这里 将连接数据库的代码进行统一化管理
8Dim conn As SQLConnection
9Dim Cfg as HashTable
10Cfg = Context.GetConfig("appsettings")
11Conn = New SQLConnection(cfg("Conn"))
12GetConn=Conn
13end function
14
15sub WritePage(start as integer,file as string,intLen as integer,intPageCount as integer,intRecCount as integer)
16'这个是一个 可移植 的 分页的程序
17'进行分页处理
18dim strWrite as string
19strWrite="<table border=1 width=100%><tr><td>"
20response.write(strWrite)
21
22if start=0 then
23strWrite="首页"
24else
25strWrite="<a href='" & file & "?start=0'>首页</a>"
26end if
27response.write(strWrite)
28
29if start>=1 then
30strWrite="<a href='" & file & "?start=" & cStr(start-intLen) & "'>上页</a>"
31else
32strWrite="上页"
33end if
34response.write(strWrite)
35
36if start+intLen<intRecCount then
37'还没有到最后一页数据
38strWrite="<a href='" & file & "?start=" & cStr(start+intLen) & "'>下页</a>"
39else
40strWrite="下页"
41end if
42response.write(strWrite)
43
44if start+intLen<intRecCount then
45'还没有到最后一页数据
46strWrite="<a href='" & file & "?start=" & cStr((intPageCount-1)*intLen) & "'>末页</a>"
47else
48strWrite="末页"
49end if
50response.write(strWrite & "</td><td>")
51
52strWrite="当前共有文章" & Cstr(intRecCount) & "篇,现在是第<font color=red>" & cStr((Start/intLen)+1) & "/" & cstr(intPageCount) & "</font>页"
53response.write(strWrite)
54strWrite="</td></tr></table>"
55response.write(strWrite)
56end sub
57</script>
大家在asp.net 中一定要注意,我们在asp.net 中定义函数的时候,一定要注意必须在
1<script ..="" runat="server"></script>