asp+ version of the simple Message board production (iii)

Source: Internet
Author: User
Tags implement integer
asp+ version of the simple Message board production (iii)
/*
Tofu production, are fine
Http://www.asp888.net Tofu Technology Station
If reproduced, please retain the copyright information
*/
Now it's time to show that the show is actually very simple, as long as I have seen tofu before the article friends should know how to write this program, but I want to emphasize here is the paging program, I also like everyone, at the beginning, want to take advantage of the Web form data binding function, but unfortunately, Although it is easy to implement bindings and pagination with a DataGrid, the DataGrid obviously forms a grid that is not appropriate for the message board, dblist to the program form that can fit into the message board.
But I've been looking for a long time to find out how to implement pagination, and then I found PagedDataSource on MSDN. Look at his Class member. All of the paging features that I want have been provided by him, but I am in the process of debugging, but how can not Through, estimate is and my PDC version of the reason, this time, I think of happy (note: Netizen name, he had suggested I directly install NGWS beta1 and Vs7 beta1):)

I hope that if you succeed in debugging on BETA1, you must tell tofu

There is no other way, I have to use my old ways, using the program to control, God, I do not want to, but I really have no other way.

Please see 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 ("appsettings")
Conn = New SqlConnection (cfg ("Conn"))

Dim strSQL As String
' There is no way, so to get the total number of records
' According to Ngws's help, it seems like there's a pageddatasource that's pretty powerful.
' But I just don't know how to use it and I've never seen it in his case.
Strsql= "SELECT COUNT (*) as Ccount from Msgboard"
sqlcmd = New SQLCommand (strsql,conn)
sqlcmd. Activeconnection.open ()
Sqlcmd.execute (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 ()
Sqlcmd.execute (Sqlread)


If IsNumeric (Request.QueryString ("Start")) Then
Intstart=cint (Request.QueryString ("Start")) ' data from this page makes position
Else
Intstart=0
End If

intlen=10 ' number of data to display per page
' The following calculates the page number of pages for the current record
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 resulting sqlread back to the position specified by the start
For I=0 to IntStart-1
Sqlread.read ()
Next
End Sub
Sub Writepage (Start as integer,file as String)
' Page-handling
Dim strwrite As String
Strwrite= "<table border=1 width=100%><tr><td>"
Response.Write (Strwrite)

If Start=0 Then
Strwrite= "Home"
Else
Strwrite= "<a href=" "& File &"? start=0 ' > Home </a> '
End If
Response.Write (Strwrite)

If Start>=1 Then
Strwrite= "<a href=" "& File &"? start= "& CStr (Start-intlen) &" "> Page </a>"
Else
strwrite= "on page"
End If
Response.Write (Strwrite)

If Start+intlen<intreccount Then
' Not yet to the last page of data
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
' Not yet to the last page of data
strwrite= "<a href= '" & File & "? start=" & CStr ((intPageCount-1) *intlen) & "' > Last </a>"
Else
Strwrite= "Last"
End If
Response.Write (Strwrite & "</td><td>")

strwrite= "Current Message" & CStr (Intreccount) & ", now <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 Technology Station __aspx Station __ View message </title>
<link rel= "stylesheet" type= "Text/css" href= "/doufu.css" >
</HEAD>
<BODY>
<a href= "http://www.asp888.net" > Tofu 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 for
%>
<div align=center>
<table border=1 width=80%>
<tr>
&LT;TD Width=10%> said </td>
<td width=40%><%=sqlread ("nickname")%></td>
&LT;TD Width=10%>ip Address </td>
&LT;TD width=10%><%=sqlread ("ipaddr")%></td>
</tr>
<tr>
&LT;TD width=10%> Contact Way </td>
&LT;TD width=90% colspan=3><%=sqlread ("email")%></td>
</tr>
<tr>
&LT;TD width=10%> Message Theme </td>
&LT;TD width=90% colspan=3><%=sqlread ("Msgtitle")%>----<font color=red><%=sqlread ("msgTime")% ></font></td>
</tr>
<tr>
&LT;TD width=10%> Message Content </td>
&LT;TD width=90% Colspan=3><%=server. HTMLEncode (Sqlread ("Msgcontent"))%></td>
</tr>
</table>
</div>
<p></p>
<%next%>
</body>
Finally finished:)

Conclusion:
After you have read three articles, the entire message version of the program has been all finished, objectively speaking, through this program we can not fully appreciate the asp+ to bring us all the exciting features, but also a lot of functions now seems to be in the propaganda stage, but after all, now is the Beta1 stage , I believe that when the official version of the launch, we can see a new Web-oriented programming of the. NET Platform



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.