[
繁体中文
]
登录
立即注册
关闭
安全选项
找回密码
记住我
我的中心
登录或注册新用户,开通自己的个人中心
切换到窄版
首页
会员
搜索
帮助
51Aspx
快速搜索
帖子标题
作者
版块
.Net源码论坛
»
Asp.net交流讨论区
»
技术文章
»
本人原创-"DataList分页功能"
Asp.net交流讨论区
技术问答
Azure技术交流区
.Net项目、服务交易区
求职招聘区
技术文章
视频发布区
常用工具下载
Asp.net专题讨论区
Windows Phone讨论专区
Ajax/Atlas无刷新技术
面向对象开发
ADO.net讨论区
控件专题讨论
网站帮助
金币与积分(原共享分)
关于源码
会员介绍
关于51Aspx
环境搭建
51aspx站务相关
常见问题&帮助
站内活动、公告
反馈/建议
[垃圾箱/恶性广告]
返回列表
1
2
3
4
5
6
7
8
»
/ 9
下一页
查看:
49778
|
回复:
89
本人原创-"DataList分页功能"
[复制链接]
发送短消息
UID
54
帖子
220
精华
3
经验值
276
论坛积分
0 分
性别
来自
在线时间
5050
注册时间
2007-06-07
最后登录
2016-08-24
查看公共资料
搜索主题
搜索帖子
一半情弧
论坛积分
0 分
注册时间
2007-06-07
楼主
字体大小:
t
T
发表于
2007-06-11 22:19
|
只看楼主
[设计页面中的源代码:]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DataList分页功能</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center">
<div align="center">
<table border="0" style="width: 1px">
<tr>
<td nowrap="nowrap" style="width: 949px; height: 19px" bgcolor="gray">
<div align="center" style="font-weight: bold; font-size: 15px; font-family: 'Courier New'; color: white;">
学生寝室管理系统->留言板</div>
</td>
</tr>
<tr>
<td style="height: 33px; width: 949px;">
<div align="center">
<asp:DataList ID="mydatalist" runat="server" style="font-size: 13px">
<ItemTemplate>
<div align="center">
<div align="center">
<div align="center">
<table border="0" style="width: 810px; height: 293px; font-size: 14px;">
<tr>
<td style="width: 136px; color: white; font-weight: bold; font-size: 14px; height: 19px;" bgcolor="dimgray" align="center">
留言标题</td>
<td align="center" style="width: 1813px; color: white; font-weight: bold; font-size: 14px; height: 19px;" bgcolor="dimgray">
<%#DataBinder.Eval(Container.DataItem, "title")%></td>
<td align="left" style="width: 763px; height: 19px;" bgcolor="dimgray">
</td>
</tr>
<tr>
<td style="width: 136px; height: 228px;">
<div align="left">
<table border="0" style="width: 205px">
<tr>
<td width="216" style="height: 125px">
<div align="center">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"userface","images/userface/{0}.gif") %>' /></div>
</td>
</tr>
<tr>
<td nowrap="nowrap">
<div align="left">
<font color="#000033"> 姓名:</font><%#DataBinder.Eval(Container.DataItem, "username")%></div>
</td>
</tr>
<tr>
<td nowrap="nowrap">
<font color="#000033">身份:</font><%#DataBinder.Eval(Container.DataItem, "usershenfen")%></td>
</tr>
<tr>
<td nowrap="nowrap" style="height: 21px">
<div align="left">
<font color="#000033">性别:</font><%#DataBinder.Eval(Container.DataItem, "usersex")%></div>
</td>
</tr>
<tr>
<td nowrap="nowrap">
<div align="left">
<font color="#000033"> 地址:</font><%#DataBinder.Eval(Container.DataItem, "useraddress")%></div>
</td>
</tr>
<tr>
<td nowrap="nowrap">
<div align="left">
<font color="#000033"> E-mail:</font><%#DataBinder.Eval(Container.DataItem, "useremail")%></div>
</td>
</tr>
</table>
</div>
</td>
<td style="height: 228px" colspan="2">
<div align="center">
<div align="center">
<div align="center">
<div align="left">
<asp:Image ID="Image2" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"img","images/emot/{0}.gif") %>' /><br />
<%#DataBinder.Eval(Container.DataItem, "content")%></div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td colspan="2" style="height: 19px" align="left">
<font color="#000033">入学时间:</font><%#DataBinder.Eval(Container.DataItem, "entertime")%> | <font color="#000033">所在系名:</font><%#DataBinder.Eval(Container.DataItem, "userxiname")%> | <font color="#000033">所学专业:</font><%#DataBinder.Eval(Container.DataItem, "userzhuanye")%> | <font color="#000033">班级名称:</font><%#DataBinder.Eval(Container.DataItem, "classname")%></td>
<td style="width: 763px; height: 19px;" align ="left" >
<font color="#000033"> 留言时间:</font><%#DataBinder.Eval(Container.DataItem, "edittime")%> </td>
</tr>
</table>
</div>
</div>
</div>
<div align="center">
<table border="0" style="width: 808px; font-size: 14px;">
<tr>
<td align="left" style="height: 1px">
<div align="center">
<hr color="gray" />
</div>
<font color="#000033"> 回复人:</font><%#DataBinder.Eval(Container.DataItem, "rename")%>(管理员) <font color="#000033">回复时间:</font><%#DataBinder.Eval(Container.DataItem, "replytime")%></td>
</tr>
<tr>
<td nowrap="nowrap">
<div align="left">
<font color="#000033">回复内容:<asp:Image ID="Image3" runat="server" ImageAlign="AbsMiddle"
ImageUrl='<%# DataBinder.Eval(Container.DataItem,"replyimg","images/emot/{0}.gif") %>' /></font><%#DataBinder.Eval(Container.DataItem, "reply")%></div>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:DataList></div>
</td>
</tr>
<tr>
<td nowrap="nowrap" style="height: 24px; width: 949px; font-weight: bold; color: white; background-color: gray;">
<div align="center" style="font-size: 14px">
<asp:Label ID="Label1" runat="server" Text="每页显示"></asp:Label><asp:Label ID="Label3"
runat="server" ForeColor="Red" Style="font-weight: bold" Text="6"></asp:Label><asp:Label
ID="Label2" runat="server" Text="条信息 共有"></asp:Label><asp:Label ID="lblRecordCount"
runat="server" Font-Bold="True" ForeColor="Red"></asp:Label><asp:Label ID="Label4"
runat="server" Text="条记录 当前是第"></asp:Label><asp:Label ID="Labelye" runat="server"
Font-Bold="True" ForeColor="Red" Text="1"></asp:Label><asp:Label ID="Label6" runat="server"
Style="font-weight: bold" Text="/"></asp:Label><asp:Label ID="lblPageCount" runat="server"
Font-Bold="True" ForeColor="Red"></asp:Label><asp:Label ID="Label5" runat="server"
Text="页"></asp:Label>
<asp:Button ID="Button1" runat="server" BackColor="#404040"
CausesValidation="False" Height="22px" OnClick="Button1_Click" Style="font-weight: bold;
font-size: 13px; color: white" Text="上一页" Width="59px" />
<asp:Button ID="Button2" runat="server" BackColor="#404040" CausesValidation="False"
Height="22px" OnClick="Button2_Click" Style="font-weight: bold; font-size: 13px;
color: white" Text="下一页" Width="55px" />
<asp:Button ID="Button3" runat="server" BackColor="#404040" CausesValidation="False"
Height="22px" OnClick="Button3_Click" Style="font-weight: bold; font-size: 13px;
color: white" Text="首页" />
<asp:Button ID="Button4" runat="server" BackColor="#404040" CausesValidation="False"
Height="22px" OnClick="Button4_Click" Style="font-weight: bold; font-size: 13px;
color: white" Text="尾页" /></div>
</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
复制代码
一半情弧 最后编辑于 2007-06-11 22:29:14
本主题由 超级管理员 zyw19880202 于 10/13/2014 3:46:30 PM 执行 屏蔽帖子 操作
分享
转发
TOP
发送短消息
UID
54
帖子
220
精华
3
经验值
276
论坛积分
0 分
性别
来自
在线时间
5050
注册时间
2007-06-07
最后登录
2016-08-24
查看公共资料
搜索主题
搜索帖子
一半情弧
论坛积分
0 分
注册时间
2007-06-07
沙发
字体大小:
t
T
发表于
2007-06-11 22:31
|
只看楼主
回复: 本人原创-"DataList分页功能"
代码隐藏页中的源代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;//引进连接Sql Server的命名空间
public partial class _Default : System.Web.UI.Page
{
SqlCommand cmd,cmd1;
SqlConnection cn;
string strsql;
SqlDataAdapter da;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.databindlist();
}
}
public void databindlist() //申请一个方法来绑定数据
{
cn = sqldata.createcon();//连接数据库,我把数据库封装到“sqldata”类中了
cn.Open(); //打开连接
int countpage = Convert.ToInt32(this.Labelye.Text); //获取当前页面
strsql = "select * from guestbook order by id desc "; //Sql查询语句
da = new SqlDataAdapter (strsql, cn);
da.Fill(ds, "Result"); //填充数据
System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource(); //封装数据绑定控件类,与分页相关的属性
ps.DataSource = ds.Tables["Result"].DefaultView;
ps.AllowPaging = true; //获取或实置一个植,指示是否在数据绑定控件中启用分页
ps.PageSize = 6; //获取或实置每页显示的条数
ps.CurrentPageIndex = countpage - 1; //获取或实置当前页的索引
this.lblPageCount.Text = Convert.ToString(ps.PageCount); //统计共有多少页
this.Button1.Enabled = true;
this.Button2.Enabled = true;
if (countpage == 1)
{
this.Button1.Enabled = false;//如果当前页等于"1",那么"Button1"不可用
}
if (countpage == ps.PageCount)
{
this.Button2.Enabled = false;//如果当前页等于"尾页",那么"Button2"不可用
}
this.mydatalist.DataSource = ps;
this.mydatalist.DataBind();//将数据源绑定到DataList
SqlCommand cmd1 = new SqlCommand ("select count(*) from guestbook", cn);
this.lblRecordCount.Text = Convert.ToString(cmd1.ExecuteScalar());//统计共有多少条记录
sqldata.pagecount = Convert.ToString(ps.PageCount);
cn.Close();//关闭连接
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Labelye.Text = Convert.ToString(Convert.ToInt32(this.Labelye.Text) - 1); //获取当前的页数
this.databindlist();
}
protected void Button2_Click(object sender, EventArgs e)
{
this.Labelye.Text = Convert.ToString(Convert.ToInt32(this.Labelye.Text) + 1); //获取下一页的页数
this.databindlist(); //绑定数据源
}
protected void Button3_Click(object sender, EventArgs e)
{
this.Labelye.Text = "1"; //获取首页
this.databindlist(); //绑定数据源
}
protected void Button4_Click(object sender, EventArgs e)
{
this.Labelye.Text =sqldata.pagecount; //获取尾页
this.databindlist(); //绑定数据源
}
}
复制代码
一半情弧 最后编辑于 2007-06-11 22:48:35
TOP
发送短消息
UID
54
帖子
220
精华
3
经验值
276
论坛积分
0 分
性别
来自
在线时间
5050
注册时间
2007-06-07
最后登录
2016-08-24
查看公共资料
搜索主题
搜索帖子
一半情弧
论坛积分
0 分
注册时间
2007-06-07
板凳
字体大小:
t
T
发表于
2007-06-11 22:32
|
只看楼主
回复:本人原创-"DataList分页功能"
有什么问题可以先看看上面的说明或大家可以一起讨论
TOP
发送短消息
UID
227
帖子
62
精华
1
经验值
84
论坛积分
2 分
性别
来自
江苏徐州
在线时间
2089
注册时间
2007-06-19
最后登录
2015-01-26
chensubo@hotmail.com
545704252
查看公共资料
搜索主题
搜索帖子
海洋
海洋
论坛积分
2 分
注册时间
2007-06-19
地板
字体大小:
t
T
发表于
2007-06-19 10:40
|
只看该用户
回复:本人原创-"DataList分页功能"
顶起,我先试试,和我原来用的分页差不多
但是没有用存储过程来的效率高的说
广告位招租...
TOP
发送短消息
UID
87
帖子
59
精华
0
经验值
59
论坛积分
0 分
性别
来自
哈(目前在京城)
在线时间
50
注册时间
2007-06-08
最后登录
2015-10-27
查看公共资料
搜索主题
搜索帖子
shun1984
刚来的民工
论坛积分
0 分
注册时间
2007-06-08
五楼
字体大小:
t
T
发表于
2007-06-29 13:12
|
只看该用户
回复:本人原创-"DataList分页功能"
这个是你原创的??。。。 这个方法我用过好多次了。。不过我是抄袭的
我只是民工。
TOP
发送短消息
UID
13023
帖子
12
精华
0
经验值
15
论坛积分
15 分
性别
来自
在线时间
489
注册时间
2008-04-10
最后登录
2014-07-22
查看公共资料
搜索主题
搜索帖子
li694079669
论坛积分
15 分
注册时间
2008-04-10
六楼
字体大小:
t
T
发表于
2008-06-10 21:20
|
只看该用户
回复:本人原创-"DataList分页功能"
谢谢啊
TOP
发送短消息
UID
20406
帖子
2
精华
0
经验值
2
论坛积分
2 分
性别
来自
在线时间
20
注册时间
2008-06-01
最后登录
2013-03-12
查看公共资料
搜索主题
搜索帖子
lc8886
论坛积分
2 分
注册时间
2008-06-01
七楼
字体大小:
t
T
发表于
2008-06-11 09:22
|
只看该用户
回复: 本人原创-"DataList分页功能"
能否把SQLDATA页面源码贴上来!谢谢
TOP
发送短消息
UID
20406
帖子
2
精华
0
经验值
2
论坛积分
2 分
性别
来自
在线时间
20
注册时间
2008-06-01
最后登录
2013-03-12
查看公共资料
搜索主题
搜索帖子
lc8886
论坛积分
2 分
注册时间
2008-06-01
八楼
字体大小:
t
T
发表于
2008-06-11 12:30
|
只看该用户
回复:本人原创-"DataList分页功能"
呵呵问题解决,可以更简单的写!
TOP
发送短消息
UID
19450
帖子
28
精华
0
经验值
28
论坛积分
28 分
性别
来自
离海洋最远的城市,不是天涯!
在线时间
0
注册时间
2008-05-25
最后登录
2010-07-04
查看公共资料
搜索主题
搜索帖子
william9527
论坛积分
28 分
注册时间
2008-05-25
九楼
字体大小:
t
T
发表于
2008-06-12 02:46
|
只看该用户
回复:本人原创-"DataList分页功能"
似乎还是一开始就读入整个的表,能不能一开始只读取相应页的内容,比如一开始就读第一页的内容,这样可以减少数据库的读取量,还有就是,不然随着你的数据库的增加性能还是不怎么样!看到了在SQL Server 2005上用RowNumber()函数的分页例子,可以百度一下,呵呵。
TOP
发送短消息
UID
2916
帖子
19
精华
0
经验值
19
论坛积分
19 分
性别
来自
在线时间
25
注册时间
2007-12-17
最后登录
2008-08-19
查看公共资料
搜索主题
搜索帖子
zero18
论坛积分
19 分
注册时间
2007-12-17
十楼
字体大小:
t
T
发表于
2008-06-12 11:29
|
只看该用户
回复:本人原创-"DataList分页功能"
看看,学习
TOP
上一主题
|
下一主题
返回列表
1
2
3
4
5
6
7
8
»
/ 9
下一页
高级编辑器
B
Color
Image
Link
Quote
Code
Smilies
默认表情
你需要登录后才可以发帖
登录
|
注册
发表回复
查看背景广告
隐藏
发新主题
Asp.net交流讨论区
技术问答
Azure技术交流区
.Net项目、服务交易区
求职招聘区
技术文章
视频发布区
常用工具下载
Asp.net专题讨论区
Windows Phone讨论专区
Ajax/Atlas无刷新技术
面向对象开发
ADO.net讨论区
控件专题讨论
网站帮助
金币与积分(原共享分)
关于源码
会员介绍
关于51Aspx
环境搭建
51aspx站务相关
常见问题&帮助
站内活动、公告
反馈/建议
[垃圾箱/恶性广告]
TOP
设置头像
个人资料
更改密码
用户组
收藏夹
积分
我的主题
我的回复
我的精华
我的附件
我的收藏
我的源码
基本状况
流量统计
客户软件
发帖量记录
版块排行
主题排行
发帖排行
积分排行
在线时间
免费源码
商业源码
我的资源