Http://www.asp888.net bean curd technology station
In the previous article, we reference a function package file func. aspx. In this article, we will explain in detail this func. aspx file.
<% @ Assembly Name = "System. Net" %>
<% @ Import Namespace = "System. Net" %>
<% @ Import Namespace = "System. IO" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. SQL" %>
I will not talk about these import operations. The commonly used NameSpace explanations in the previous article sp + have already been involved.
<Script language = "VB" runat = server>
Function replaceSql (str1 as string) as string
When using SQL statements in asp.net, the "" number problem also occurs. Therefore, the replace function is used to convert "" ""
ReplaceSql = replace (str1 ,"","")
End function
Function GetConn () as SQLConnection
The Code connecting to the database is managed in a unified manner.
Dim conn As SQLConnection
Dim Cfg as HashTable
Cfg = Context. GetConfig ("etettings ")
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)
This is a portable paging program.
Paging
Dim strWrite as string
StrWrite = "<table border = 1 width = 100%> <tr> <td>"
Response. write (strWrite)
If start = 0 then
StrWrite = "Homepage"
Else
StrWrite = "<a href =" & file &"? Start = 0> homepage </a>"
End if
Response. write (strWrite)
If start> = 1 then
StrWrite = "<a href =" & file &"? Start = "& cStr (start-intLen) &"> previous page </a>"
Else
StrWrite = "Previous Page"
End if
Response. write (strWrite)
If start + intLen <intRecCount then
No data to the last page
StrWrite = "<a href =" & file &"? Start = "& cStr (start + intLen) &"> next page </a>"
Else
StrWrite = "next page"
End if
Response. write (strWrite)
If start + intLen <intRecCount then
No data to the last page
StrWrite = "<a href =" & file &"? Start = "& cStr (intPageCount-1) * intLen) &"> last </a>"
Else
StrWrite = "last page"
End if
Response. write (strWrite & "</td> <td> ")
StrWrite = "A total of articles" & Cstr (intRecCount) & ", which is <font color = red>" & cStr (Start/intLen) + 1) & "/" & cstr (intPageCount) & "</font> page"
Response. write (strWrite)
StrWrite = "</td> </tr> </table>"
Response. write (strWrite)
End sub
</Script>
When defining a function in asp.net, you must note that the function must be in <script runat = server...>.
Define the function, instead of defining the function between <% and %> like asp. The advantage of doing so is that the function definition is simple and clear, and the program is readable.
But one inconvenient thing is that, in <script>..., it is not as convenient as in <%> to call HTML
Code, but must use Response. Write (ss), this is an inconvenient place