运行效果:前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProjectList.aspx.cs" Inherits="LoveFundWeb.后台.ProjectList" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link href="../Content/bootstrap.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div style="width:80%;margin:50px auto">
<h1 style="text-align:center">项目列表</h1>
<table class="table table-bordered table-hover">
<tr>
<th>项目编号</th>
<th>项目名称</th>
<th>需要金额</th>
<th>预计天数</th>
<th>类别ID</th>
<th>所在省份</th>
<th>所在城市</th>
<th>项目简介</th>
<th>项目详情</th>
<th>通过状态</th>
<th>操作</th>
</tr>
<asp:Repeater ID="rpProjectList" runat="server">
<ItemTemplate>
<tr>
<td><%# Eval("ProId") %></td>
<td><%# Eval("ProName") %></td>
<td><%# Eval("AmountRequired") %></td>
<td><%# Eval("ExpectedDays") %></td>
<td><%# Eval("CategoryID") %></td>
<td><%# Eval("Province") %></td>
<td><%# Eval("City") %></td>
<td><%# Eval("ProjectBrief") %></td>
<td><%# Eval("ProjectDetails") %></td>
<%--通过状态--%>
<td>
<asp:Label ID="Label1" runat="server" ForeColor ='<%# int.Parse(Eval("PassState").ToString())==0?System.Drawing.Color.Red:System.Drawing.Color.Green %>'>
<%# int.Parse(Eval("PassState").ToString())==0?"未通过":"通过" %>
</asp:Label>
</td>
<td>
<a href ="UpdatePassState.aspx?ProId=<%# Eval("ProId") %>&PassState=<%# Eval("PassState") %>"
style='color:<%# int.Parse(Eval("PassState").ToString())==0?"green":"red" %>'>
<%# int.Parse(Eval("PassState").ToString())==0?"通过":"不予通过" %>
</a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<table style="width: 520px; height: 32px">
<tr>
<td colspan="2" style="width: 436px; height: 39px">
当前第<asp:Label ID="lblCurrentPage" runat="server" Width="48px"></asp:Label>页 共<asp:Label
ID="lblCountPage" runat="server"></asp:Label>页</td>
<td colspan="2" style="width: 34px; height: 39px">
<asp:Button ID="btnFirstPage" runat="server" Text="首页" OnClick="btnFirstPage_Click"/></td>
<td style="width: 18px; height: 39px">
<asp:Button ID="btnUpPage" runat="server" Text="上一页" OnClick="btnUpPage_Click"/></td>
<td style="width: 27px; height: 39px">
<asp:Button ID="btnNextPage" runat="server" Text="下一页" Onclick="btnNextPage_Click"/></td>
<td style="width: 17px; height: 39px">
<asp:Button ID="btnLastPage" runat="server" EnableTheming="True" Text="尾页" Onclick="btnLastPage_Click"/></td>
</tr>
</table>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace LoveFundWeb.后台
{
public partial class ProjectList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblCurrentPage.Text = "1";
BindPoruduct();
}
}
private void BindPoruduct()
{
int curPage = Convert.ToInt32(this.lblCurrentPage.Text);//当前第一页
//创建了PagedDataSource对象
PagedDataSource pds = new PagedDataSource();
//获取数据源
pds.DataSource = ProjectManage.GetAllProjects();
pds.AllowPaging = true; //允许分页功能
pds.PageSize = 2; //每页显示的行数
pds.CurrentPageIndex = curPage - 1; //当前的页数
this.lblCountPage.Text = Convert.ToString(pds.PageCount); //总页数
this.btnFirstPage.Enabled = true;
this.btnUpPage.Enabled = true;
this.btnNextPage.Enabled = true;
this.btnLastPage.Enabled = true;
if (curPage == 1)
{
this.btnFirstPage.Enabled = false;
this.btnUpPage.Enabled = false;
}
if (pds.PageCount == curPage)
{
this.btnFirstPage.Enabled = true;
this.btnUpPage.Enabled = true;
this.btnLastPage.Enabled = false;
this.btnNextPage.Enabled = false;
}
//绑定数据源
rpProjectList.DataSource = pds;
rpProjectList.DataBind();
}
protected void btnFirstPage_Click(object sender, EventArgs e)
{
this.lblCurrentPage.Text = "1";
this.BindPoruduct();
}
protected void btnUpPage_Click(object sender, EventArgs e)
{
this.lblCurrentPage.Text = Convert.ToString(Convert.ToInt32(this.lblCurrentPage.Text) - 1);
this.BindPoruduct();
}
protected void btnNextPage_Click(object sender, EventArgs e)
{
this.lblCurrentPage.Text = Convert.ToString(Convert.ToInt32(this.lblCurrentPage.Text) + 1);
this.BindPoruduct();
}
protected void btnLastPage_Click(object sender, EventArgs e)
{
this.lblCurrentPage.Text = Convert.ToString(this.lblCountPage.Text);
this.BindPoruduct();
}
}
}