本文由中国C#技术学习中心整理 如果你对本文有不明之处请到技术论坛讨论!
以下是我程序中的一个页面,PagedDataSource封装了DataGrid,GridView的与分页相关的属性,本方法同样适用于DataList等...
CallingList.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CallingList.aspx.cs" Inherits="CallingList" %>
<!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>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center" cellpadding="2" cellspacing="1" class="tb" style="table-layout: fixed">
<tr align="center" class="tc">
<td>访问方式</td>
<td>访问时间</td>
<td>客户名称</td>
<td>客户电话</td>
<td>接待人</td>
<td>备注</td>
</tr>
<asp:Repeater ID="showCalling" runat="server">
<ItemTemplate>
<tr align="center" bgcolor="#ffffff" onmouseover="this.style.background='#f0f0f0';" onmouseout="this.style.background='#ffffff';">
<td><%# DataBinder.Eval(Container.DataItem,"c_calltype") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"c_calldate") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"c_client") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"c_tell") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"c_worker") %></td>
<td style="left: 0px; width: 100%; word-wrap: break-word; 130; 0pt"><%# DataBinder.Eval(Container.DataItem,"c_memo") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr align="right" class="tc">
<td colspan="6">
<asp:Label ID="curpage" runat="server"></asp:Label>
<asp:HyperLink ID="pre" runat="Server" Text="上一页"></asp:HyperLink>
<asp:HyperLink ID="next" runat="server" Text="下一页"></asp:HyperLink>
</td>
</tr>
</table>
<br />
<center><a href="AddCalling.aspx" target="right">添加客户访问记录</a></center>
</div>
</form>
</body>
</html>
CallingList.aspx.cs
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;
public partial class CallingList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = new clsSqlRun().getCalling().Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
int currentPage;
if (Request.QueryString["page"] != null)
{
try
{
currentPage = Int32.Parse(Request.QueryString["page"].ToString());
}
catch (Exception ex)
{
currentPage = 1;
}
}
else {
currentPage = 1;
}
pds.CurrentPageIndex = currentPage-1;
curpage.Text = "当前页:" + currentPage + " 页 共 " + pds.PageCount + " 页 ";
if (!pds.IsFirstPage)
{
pre.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentPage-1);
}
if (!pds.IsLastPage)
{
next.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentPage+1);
}
showCalling.DataSource = pds;
showCalling.DataBind();
}
}
本文由中国C#技术学习中心整理 如果你对本文有不明之处请到技术论坛讨论!