A fully functional column Management Program-this is the second application of asp.net (II)

Source: Internet
Author: User

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.