像asp相同轻松分页显示数据(c#) _c#应用

2008-02-23 05:47:00来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

代码如下:

<%@ Page Language="C#" Debug="true" %>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<Script Language="C#" runat="server">
int Record_Per_Page;//定义每页显示记录数
int nPageCount;//定义总页数
int nRecCount;//定义总记录数
int nPage;//定义当前页
void Page_Load(Object src,EventArgs e){
//取得当前页数值,并判断
if(Request["pagesize"]==null)
Record_Per_Page=9;
else
Record_Per_Page=Convert.ToInt32(Request["pagesize"]);
//连接数据库
SqlConnection conn;
conn =new SqlConnection(ConfigurationSettings.AppSettings["strconn"]);
conn.Open();

//执行SQL语句
string ConnStr="select id,name,demo,pic from download where classid=23 or classid=24 order by time desc";
SqlDataAdapter odAdapt = new SqlDataAdapter(ConnStr,conn);
DataSet DS = new DataSet();
odAdapt.Fill(DS);
DataTable DT = DS.Tables[0];
//获得总记录数
nRecCount = DT.Rows.Count;

//判断是否存在数据记录
if(nRecCount > 0){
//确定数据记录要显示的页面数
nPageCount=nRecCount/Record_Per_Page;
if(nRecCount % Record_Per_Page > 0)
nPageCount ;
if(nPage < 1)
nPage = 1;
if(nPage > nPageCount)
nPage = nPageCount;
//将页数显示到屏幕上,并作链接
for(i=1;i<=nPageCount;i ){
html=html "<a href=mblist.aspx?page=" i "&id=" classid "&classname=" Request.Params["classname"] "pagesize=" Record_Per_Page ">";
if(i==nPage)
html=html "<b>" i "</b>";
else
html=html i;
html=html "</a> ";
}
pagelist.InnerHtml=html;
html="";
//确认当前页面的开始记录和终止记录
int nStart = Record_Per_Page * (nPage - 1);
int nEnd = nStart Record_Per_Page - 1;
if(nEnd > nRecCount - 1)
nEnd = nRecCount - 1;
//在屏幕中输出记录
html="<table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=95% height=139 bgcolor=#ffffff><tr>";
int j=0;
for(i=nStart;i<=nEnd;i ){
html ="<td align=center height=180 ><table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=145><tr><td align=center><img src=http://bbs.wrclub.net/templates/" DT.Rows[i]["demo"].ToString().Trim() "/" DT.Rows[i]["pic"].ToString().Trim() " height=143 width=140 border=0 alt=" DT.Rows[i]["name"].ToString().Trim() "></td></tr><tr><td width=100% background=images/mbbg.gif><table border=0cellpadding=0cellspacing=0width=100%><tr><td width=50%><a href=http://bbs.wrclub.net/templates/" DT.Rows[i]["demo"].ToString().Trim() "/ target=_blank><img src=images/view.gif border=0></a></td><td width=50% align=right><a href=mbdown.aspx?id=" DT.Rows[i]["id"] " target=_blank><img src=images/down.gif border=0></a></td></tr></table></td></tr></table></td>";
j ;
if(j%3==0)
html ="</tr><tr>";
}
html ="</tr></table>";
mblist.InnerHtml=html;
html="";
}
conn.Close();
}
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=Request.Params["classname"]%>:网人俱乐部</title>
<meta name="Keywords" CONTENT="学习,免费资源,asp,jsp,flash,photoshop,社区,论坛,同学录,电子图书,网站建设,宣传,推广,聊天,数据库,经验心得,游戏,game,电子超市,网人交流论坛,插件,下载">
<meta name="description" CONTENT="提供网站建设、研发方面的学习资料、经验心得,同时提供免费的电子书籍、网站免费资源、制作工具、插件、滤镜,网站更有网上电子超市、论坛、网人交流论坛">
<link rel="stylesheet" type="text/css" href="style.css"><link rel="Shortcut Icon" href="favicon.ico">
</head>
<body topmargin="0" leftmargin="0"><form runat=server action="?id=22&classname=模板中央">
<!-- #Include File="top.inc" -->
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="778" height="92">
<tr>
<td width="375" height="92" rowspan="2"><img src="http://www.knowsky.com/images/wrclub_l<%=Request.Params["id"]%>.jpg" width="375" height="92">
</td>
<td height="24" width="403" background="images/bg3.gif"> <span id="myclass" runat="server"></span></td>
</tr>
<tr>
<td width="403" height="68" valign="top">
<!-- #Include File="bbslogin.inc" --> </td>
</tr>
</table>
<table width="778" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20" background="images/bg5.gif"><img src="http://www.knowsky.com/images/bg5.gif" width="7" height="24"></td>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: 利用c#进行autocad的二次研发(一)_c#应用

下一篇: 用c#下的raw socket编程实现网络封包监控_c#应用