Production of simple message boards in asp + (3)

Source: Internet
Author: User

Http://www.asp888.net bean curd technology station

Now, the display is actually very simple. Anyone who has read the previous article on tofu should know how to write this
Program, but here I want to emphasize the paging program. I also want to use web form at the beginning.
But unfortunately, although it is very easy to bind and pagination with the datagrid
Apparently, the form of Grid is obviously not suitable for the program such as the message board, and DBList can be suitable for the program form of the message board.
However, I have not found a program for implementing Paging for a long time.
Later, I found PagedDataSource on MSDN and looked at his Class Member.
He has provided all the functions, but I cannot pass the debugging process. It is estimated that it is the reason for my PDC version,
At this time, I was very happy (Note: I was advised to install NGWS beta1 and Vs7 beta1 directly ):)

I hope you will tell Bean curd after debugging on Beta1.

There is no other way. I have to use my old method to control it with a program. God, I don't want to do this, but I really have nothing else.
Solution

Please refer to the program:
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Web. Security" %>
<% @ Import Namespace = "System. Web. UI" %>
<% @ Import Namespace = "System. Data. SQL" %>
<HTML> <HEAD>
<Script runat = "server" language = "VB">
Dim sqlRead as SQLDataReader
Dim intStart as integer
Dim intLen as integer
Dim intPageCount as integer
Dim intRecCount as integer
Sub Page_Load (Src As Object, E As EventArgs)
Dim conn As SQLConnection
Dim Cfg as HashTable
Dim sqlcmd As SQLCommand

Cfg = Context. GetConfig ("etettings ")
Conn = New SQLConnection (cfg ("Conn "))

Dim strSQL as string
There is really no way to get the total number of records.
According to the help of NGWS, it seems that a PagedDataSource is quite powerful.
But I don't know how to use it. I have never seen an example of using it.
StrSQL = "select count (*) as ccount from msgBoard"
Sqlcmd = New SQLCommand (strSQL, conn)
Sqlcmd. ActiveConnection. Open ()
Sql0000.exe cute (sqlRead)
SqlRead. Read ()
IntRecCount = cInt (sqlRead ("ccount "))
Sqlcmd. ActiveConnection. Close ()
StrSQL = "select * from msgBoard order by msgid desc"
Sqlcmd = New SQLCommand (strSQL, conn)
Sqlcmd. ActiveConnection. Open ()
Sql0000.exe cute (sqlRead)


If isNumeric (request. querystring ("start") then
IntStart = Cint (request. querystring ("start") data starting position on this page
Else
IntStart = 0
End if

IntLen = 10 number of data to be displayed per page
The page number of the current record is calculated as follows:
If (intRecCount mod intLen) = 0 then
IntPageCount = intRecCount/intLen
Else
IntPageCount = (intRecCount-(intRecCount mod intLen)/intLen + 1
End if
Dim I as integer
Move the obtained sqlRead back to the position specified by start.
For I = 0 to intStart-1
SqlRead. read ()
Next
End sub
Sub WritePage (start as integer, file as string)
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 = "current total messages" & Cstr (intRecCount) & ", now the <font color = red>" & cStr (intStart/intLen) + 1) & "/" & cstr (intPageCount) & "</font> page"
Response. write (strWrite)
StrWrite = "</td> </tr> </table>"
Response. write (strWrite)
End sub
</Script>
<Title> tofu Technical Station _ aspx substation _ view comments </title>
<Link rel = "stylesheet" type = "text/css" href = "/doufu.css">
</HEAD>
<BODY>
<A href = "http://www.asp888.net"> bean curd technology station </a> family dedication <br>
<%
WritePage (intStart, "a. aspx ")
Dim atEnd as boolean
%>
<% For I = 0 to intLen-1 %>
<%
AtEnd = sqlRead. read ()
If not atEnd then exit
%>
<Div align = center>
<Table border = 1 width = 80%>
<Tr>
<Td width = 10%> </td>
<Td width = 40%> <% = sqlRead ("nickname") %> </td>
<Td width = 10%> ip address </td>
<Td width = 10%> <% = sqlRead ("IPAddr") %> </td>
</Tr>
<Tr>
<Td width = 10%> Contact Information </td>
<Td width = 90% colspan = 3> <% = sqlRead ("email") %> </td>
</Tr>
<Tr>
<Td width = 10%> message topic </td>
<Td width = 90% colspan = 3> <% = sqlRead ("msgTitle") %> ---- <font color = red> <% = sqlRead ("msgTime ") %> </font> </td>
</Tr>
<Tr>
<Td width = 10%> message content </td>
<Td width = 90% colspan = 3> <% = server. HTMLEncode (sqlRead ("msgContent") %> </td>
</Tr>
</Table>
</Div>
<P> </p>
<% Next %>
</Body>
</Html>
Finally completed :)

Conclusion:
After reading three articles, the entire message board program has been fully explained. Objectively speaking, through this program
We still cannot fully appreciate all the exciting functions that asp + brings to us, and many other functions seem to be available now.
The publicity stage, but after all, it is now the Beta1 stage. I believe that when the official version is launched, we can see a new
. Net platform for Web Programming


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.