repeater留言板[转]
做了一个网站,其中的在线留言板块是用Repeater来显示留言的,这样可以用少的代码还实现多的功能,但是不知道怎么分页,要是留言过多就会使页面变的很长,能过查看众多网友的经验,知道用PagedDataSource来实现。
Repeater分页,需要依靠PagedDataSource。这个类存在于System.Web.UI.WebControls命名空间。它的作用是作为数据源与数据显示控件的中间介质。如:
数据源->PagedDataSource->数据绑定控件
之间的关系通过以下代码来实现:
PagedDataSource pds=new PagedDataSource ();
pds.DataSource=dataTable;
repeater1.DataSource=pds;
repeater1.DataBind();
这是前台aspx页代码
<div id="onlinely">
<div id="xianshily">
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<ul id="xianshi1">
<li id="xianshi2">
<ul class="ly1">
<li class="ly2">留言人:</li>
<li class="ly3"><asp:Label runat="server" ID="lyren" Text='<%#Eval("lyname") %>'></asp:Label></li>
<li class="ly4">时间:</li>
</ul>
<ul class="ly1">
<li class="ly2">留言内容:</li>
<li class="ly3"><asp:Label runat="server" ID="lynr" Text='<%#Eval("neirong") %>'></asp:Label></li>
<li class="ly4"><asp:Label runat="server" ID="lyt" Text='<%#Eval("lytime") %>'></asp:Label></li>
</ul>
<ul class="ly1">
<li class="ly2">回复:</li>
<li class="ly3"><asp:Label runat="server" ID="lyhf" Text='<%#Eval("huifu") %>'></asp:Label></li>
<li class="ly4"><asp:Label runat="server" ID="hft" Text='<%#Eval ("hftime") %>'></asp:Label></li>
</ul>
</li></ul>
</ItemTemplate>
</asp:Repeater>
</div>
<div id="pages">
<asp:hyperlink id="lnkPrev" runat="server">上页</asp:hyperlink>
<asp:hyperlink id="lnkNext" runat="server">下页</asp:hyperlink>
第<asp:label id="lblCurrentPage" runat="server"></asp:label>页
共 <asp:label id="lblTotalPage" runat="server"></asp:label>页
</div>
<div id="ly">
<ul>
<li>
<ul class="ly5">
<li class="ly6">姓名:</li>
<li class="ly7"><asp:TextBox runat="server" ID="lyname"></asp:TextBox></li>
</ul>
<ul class="ly5">
<li class="ly6">留言内容:</li>
<li class="ly7"><asp:TextBox runat="server" ID="lyneirong" TextMode="MultiLine" Wrap="true" Height="100px" Width="300px"></asp:TextBox></li>
</ul>
</li>
</ul>
<div id="tijiao">
<ul>
<li><asp:Button runat="server" ID="Button1" Text="提交" onclick="tijiao_Click" /></li>
<li><asp:Button runat="server" ID="quxiao" Text="取消" onclick="quxiao_Click" /></li>
</ul>
</div>
</div>
</div>
这是aspx.cs页代码:
using System;
using System.Data;
using System.Data.SqlClient;
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.Common;
public partial class onlinely : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["zgbygy"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
conn.Open();
string sql = "select * from liuyan order by lytime desc";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
PagedDataSource pgds=new PagedDataSource();
pgds.DataSource = ds.Tables[].DefaultView;
// 设置允许分页
pgds.AllowPaging = true;
// 每页显示为8行
pgds.PageSize = ;
// 显示总共页数
lblTotalPage.Text = pgds.PageCount.ToString();
// 当前页
int CurrentPage;
// 请求页码为不为null设置当前页,否则为第一页
if (Request.QueryString["Page"] != null)
{
CurrentPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurrentPage = ;
}
// 当前页所引为页码-1
pgds.CurrentPageIndex = CurrentPage - ;
// 显示当前页码
lblCurrentPage.Text = CurrentPage.ToString();
// 如果不是第一页,通过参数Page设置上一页为当前页-1,否则不显示连接
if (!pgds.IsFirstPage)
{
// Request.CurrentExecutionFilePath为当前请求虚拟路径
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + );
}
// End If
// 如果不是最后一页,通过参数Page设置下一页为当前页+1,否则不显示连接
if (!pgds.IsLastPage)
{
// Request.CurrentExecutionFilePath为当前请求虚拟路径
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + );
}
Repeater1.DataSource =pgds;
Repeater1.DataBind();
cmd.Dispose();
conn.Close();
}
protected void tijiao_Click(object sender, EventArgs e)
{
try
{
conn.Open();
string sql = "insert into liuyan (lyname,neirong,lytime) values ('" +lyname.Text +"','" +lyneirong.Text + "','" + DateTime.Now + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
this.lyname.Text = "";
this.lyneirong.Text = "";
Response.Redirect("onlinely.aspx");
}
catch
{
}
}
protected void quxiao_Click(object sender, EventArgs e)
{
this.lyname.Text = "";
this.lyneirong.Text = "";
}
public void xinashi(object sender, EventArgs e)
{
conn.Open();
string sql = "select * from liuyan";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
Repeater1.DataSource = ds;
Repeater1.DataBind();
cmd.Dispose();
conn.Close();
}
}
repeater留言板[转]的更多相关文章
- Repeater+AspNetPager+Ajax留言板
最近想要巩固下基础知识,于是写了一个比较简单易懂实用的留言板. 部分样式参考了CSDN(貌似最近一直很火),部分源码参照了Alexis. 主要结构: 1.前期准备 2.Repeater+AspNetP ...
- AngularJs学习笔记(制作留言板)
原文地址:http://www.jmingzi.cn/?post=13 初学Anjularjs两天了,一边学一边写的留言板,只有一级回复嵌套.演示地址 这里总结一下学习的过程和笔记.另外,看看这篇文章 ...
- dd——留言板再加验证码功能
1.找到后台-核心-频道模型-自定义表单 2.然后点击增加新的自定义表单 diyid 这个,不管他,默认就好 自定义表单名称 这个的话,比如你要加个留言板还是投诉建议?写上去呗 数据表 这个不要碰, ...
- asp.net留言板项目源代码下载
HoverTree是一个asp.net开源项目,实现了留言板功能. 前台体验网址:http://hovertree.com/guestbook/ 后台请下载源代码安装. 默认用户名:keleyi 默认 ...
- html的留言板制作(js)
这次留言板运用到了最基础的localstorage的本地存储,展现的效果主要有: 1.编写留言2.留言前可以编辑自己的留言昵称.不足之处: 1.未能做出我喜欢的类似于网易的叠楼功能. 2.未能显示评论 ...
- 11月8日PHP练习《留言板》
一.要求 二.示例页面 三.网页代码及网页显示 1.denglu.php 登录页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...
- [课程设计]Scrum 3.7 多鱼点餐系统开发进度(留言板选择方案)
Scrum 3.7 多鱼点餐系统开发进度(留言板选择方案) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点餐系统W ...
- [课程设计]Scrum 3.6 多鱼点餐系统开发进度(用户测试反馈页面构思&留言板设计)
Scrum 3.6 多鱼点餐系统开发进度(用户测试反馈页面构思&留言板设计) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团 ...
- 用 Express4 写一个简单的留言板
Knowledge Dependence:阅读文本前,你需要熟悉 Node.js 编程.Express 以及相关工具和常用中间件的使用. Node.js 以其单线程异步非阻塞的特点,越来越被广大的 W ...
随机推荐
- C# MDI子窗体互相操作
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- maven常用插件pom配置
一.问题描述: 部署一个maven打包项目时,jar包,依赖lib包全部手动上传至服务器,然后用maven部署报错:Exception in thread "main" java. ...
- lkx开发日志1-项目前的准备
遇到的问题 不了解github的使用 不能熟练的用Markdown编辑,比如:放入图片 虚拟机的认知也还是有点模糊 解决的方法 参照老师博文给出的链接,好好学习实操一遍 多请教组员,很多小问题便迎刃而 ...
- linux/unix 编程手册 fork()函数
父进程通过fork()函数创建子进程,将父进程数据段和栈的内容拷贝到子进程中,子进程执行程序execve创建新程序,调用exit函数退出到等待wait(),挂起父进程, 父子进程享用相同的程序文本段. ...
- 改变this指针的apply,call,bind的区别
apply.call 在 javascript 中,call 和 apply 都是为了改变某个函数运行时的上下文(context)而存在的,换句话说,就是为了改变函数体内部 this 的指向. Jav ...
- 浅谈HTTPS和SSL/TLS协议的背景和基础
相关背景知识要说清楚HTTPS协议的实现原理,至少要需要如下几个背景知识.大致了解几个基础术语(HTTPS.SSL.TLS)的含义大致了解HTTP和TCP的关系(尤其是"短连接"和 ...
- Apache与Tomcat的整合
一 Apache与Tomcat比较联系 apache支持静态页,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是由 ...
- C++之路进阶——codevs3566(紧急疏散)
3566 紧急疏散 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 发生了火警,所有人员需要紧急疏散!假设每个房间是一 ...
- UVALive 7146 Defeat the Enemy(贪心+STL)(2014 Asia Shanghai Regional Contest)
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others. ...
- C#调用windows API的一些方法
使用C#调用windows API(从其它地方总结来的,以备查询) C#调用windows API也可以叫做C#如何直接调用非托管代码,通常有2种方法: 1. 直接调用从 DLL 导出的函数. 2. ...