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 ...
随机推荐
- apche配置后报错(Forbidden)没有权限
apche如何配置虚拟目录及虚拟目录的权限 <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow ...
- ExpandoObject动态类生成属性转json
using System; using System.Collections; using System.Collections.Generic; using System.Collections.O ...
- MQTT——服务器搭建(一)
MQTT介绍 MQTT,是IBM推出的一种针对移动终端设备的基于TCP/IP的发布/预订协议,可以连接大量的远程传感器和控制设备: 轻量级的消息订阅和发布(publish/subscribe)协议 建 ...
- SpringMVC常用配置-添加静态资源处理器-针对SpringMVC中静态资源无法访问的问题
- linux------------centos防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 你可以用rpm -qa | grep iptables来查看,一般会出现两个一个是iptables 另一个是iptables. ...
- 总结ThinkPHP使用技巧经验分享(二)
循环输出volist 还有别名 iterate 模版赋值:$User = D('User')$list = $User->findAll()$this->assign('list',$li ...
- (转)学习使用Jmeter做压力测试(三)--数据库测试
数据库测试 JMeter可以做为Web服务器与浏览器之间的代理网关,以捕获浏览器的请求和Web服务器的响应,这样就可很容易的生成性能测试脚本. 根据脚本,JMeter可通过线程组来模拟真实用户对Web ...
- New Concept English 1-10
Lesson 10 The loss of Titanic The great ship, Titanic, sailed for New York from Southampton on April ...
- [原创]Visual Studio 使用 Just My Code引起无法断点
今天遇到的问题,同样的代码,在一台机器上用Release配置可以命中断点,在另一台上用Release断点就都失效了.后来发现是因为断点失效的机器上设置了Just My Code.在Debug-Opti ...
- 2.多线程-GCD
1.基本概念 同步任务:在当前线程按顺序执行,不开启新的线程 异步任务:有开新线程的欲望 串行队列:一个一个执行 并行队列:多个任务同时执行 --------------------------- ...