留言本(3)主页
来源:互联网 发布:三毛淘宝小号网址 编辑:程序博客网 时间:2024/05/01 13:09
主页的功能主要是显示留言(用Repeater),进行分页处理,各个链接实现。
源码如下:
<%@ 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>无标题页</title>
<style type="text/css" >
table {FONT-SIZE: 12px;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<table border="1" style="width: 100%; height: 18%" bordercolor="#ffcc33">
<tr>
<td align="center" valign="top" style=" height: 104px;">
<asp:Image ID="Image1" runat="server" ImageUrl="~/img/tupian.gif" /></td>
</tr>
</table>
</div><table border="1" bordercolor="#ffcc00" style="width: 100%">
<tr>
<td bordercolordark="#ffff33" style="width: 461px; height: 6px; font-weight: bold; color: #666600;" align="left">
当前位于:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>页 共<asp:Label
ID="Label2" runat="server" Text="Label"></asp:Label>页</td>
<td style="width: 90px; height: 6px">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="first" OnClick="LinkButton1_Click">首页</asp:LinkButton></td>
<td style="width: 71px; height: 6px">
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="pre" OnClick="LinkButton2_Click">上一页</asp:LinkButton></td>
<td style="width: 74px; height: 6px;">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="next" OnClick="LinkButton3_Click">下一页</asp:LinkButton>
<td style="width: 49px; height: 6px">
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="last" OnClick="LinkButton4_Click">末页</asp:LinkButton></td>
</tr>
</table>
<table border="1" style="width: 100%" bordercolor="#ffcc00">
<tr>
<td style=" height: 16px" align="right" valign="top">
<asp:ImageButton ID="ImageButton2" runat="server" Height="47px" ImageUrl="~/img/liuyan.jpg" Width="84px" PostBackUrl="~/post.aspx" />
<asp:ImageButton ID="ImageButton1" runat="server" Height="45px" ImageUrl="~/img/woyaoguanli.jpg"
PostBackUrl="~/login.aspx" Width="80px" /> </td>
</tr>
</table>
<br />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate >
<table style="width: 100%; height: 141px" border="1" bordercolor="#ffcc33">
<tr>
<td style=" height: 29px; font-weight: bold; font-size: 20px; color: #996600;" colspan="2" valign="top" align="left">
留言主题:<%#DataBinder.Eval(Container.DataItem,"zhuti")%>
</tr>
<tr>
<td style=" height: 40px; font-weight: bold; font-size: 20px; width: 239px; color: #996600;" align="left">
留言人:<%#DataBinder.Eval(Container.DataItem,"name")%> </td>
<td style=" height: 40px; font-weight: bold; font-size: 20px; color: #996600;" align="left">
E-mail:<%#DataBinder.Eval(Container.DataItem,"email")%> </td>
</tr>
<tr>
<td style=" height: 141px; font-weight: bold; font-size: 20px; color: #996600; width: 239px;">
头像:<img src='<%#DataBinder.Eval(Container.DataItem,"picture")%>' height="90" width="90" /></td>
<td style=" height: 141px; font-weight: bold; font-size: 20px; color: #996600;" valign="top">
留言内容:<%#DataBinder.Eval(Container.DataItem,"content")%> </td>
</tr>
<tr>
<td style=" height: 32px; font-weight: bold; font-size: 20px; color: #996600;" align="right" colspan="2">
留言时间:<%#DataBinder.Eval(Container.DataItem,"time")%> </td>
</tr>
<tr>
<td style=" height: 32px;" align="right" colspan="2" valign="top">
<asp:ImageButton ID="ImageButton4" runat="server" Height="30px" ImageUrl="~/img/huifu.gif"
OnCommand='ImageButton4_Command' CommandName='huifu' CommandArgument='<%#DataBinder.Eval(Container.DataItem,"id")%>'/></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<br />
</form>
</body>
</html>
比较简单,只是绑定数据!
看看代码是怎么写的吧!主要是实现分页功能和给repeater绑定数据源。
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.OleDb;
public partial class _Default : System.Web.UI.Page
{
public DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label1.Text = "1";
DataRepeaterBind();
}
}
public void DataRepeaterBind()
{
int curpage = Convert.ToInt32(Label1.Text);
ds = DB.GetDataSet("select * from guestbook order by time desc", "guestbook"); //调用基类的方法
PagedDataSource ps = new PagedDataSource(); //实现分页的类
ps.DataSource = ds.Tables["guestbook"].DefaultView;//数据源
ps.AllowPaging = true;//允许分页
ps.PageSize = 3;
ps.CurrentPageIndex = curpage - 1;//当前页比显示页小1,因为当前页是从0开始
Label2.Text = Convert.ToString(ps.Count);//总页数
LinkButton3.Enabled = true;//首先设置都可以用
LinkButton4.Enabled = true;
LinkButton1.Enabled = true;
LinkButton2.Enabled = true;
if (curpage == 1)//为第一页时
{
LinkButton1.Enabled = false;
LinkButton2.Enabled = false;
}
if (curpage == ps.Count)//为最后一页时
{
LinkButton3.Enabled = false;
LinkButton4.Enabled = false;
}
Repeater1.DataSource = ps;
Repeater1.DataBind();
}
protected void LinkButton1_Click(object sender, EventArgs e)//当然也可以用BUTTON的argument属性
{
Label1.Text = "1";
DataRepeaterBind();//别忘记再次绑定啊!
}
protected void LinkButton2_Click(object sender, EventArgs e)// 上一页
{
Label1.Text = Convert.ToString((Convert.ToInt32(Label1.Text) - 1));//
DataRepeaterBind();
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString((Convert.ToInt32(Label1.Text) + 1));//下一页
DataRepeaterBind();
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
Label1.Text = Label2.Text;
DataRepeaterBind();
}
protected void ImageButton4_Command(object sender, CommandEventArgs e)
{
Response.Redirect("repost.aspx?id="+e.CommandArgument );
}
}
- 留言本(3)主页
- 用C++给自己的主页写留言本
- 留言本(4)写留言
- 留言本(5)回复留言
- 留言本(7)管理员管理留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- 留言本
- struts 标签之HTML详细说明
- 图解myelcipse开发EJB
- 用SOAP处理WEBSERVICE的安全性
- 学习好东东
- 我对EJB3调用原理的彻底理解
- 留言本(3)主页
- 我的第一篇文章
- 雄才、大略、贪婪、恐惧
- LCC编译器的源程序分析(27)基本语句
- 6.5
- Microsoft .NET Pet Shop 4 架构与技术分析
- 飘零无影 <--------------我喜欢这个网名..
- 留言本(4)写留言
- 杀毒后遗症