上一篇:页面执行需要长时间时向用户的提示信息 >>
使用Repeater模板 二
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="0">
<tr>
<td><font color="Highlight">编号</font></td>
<td><font color="Highlight">名称</font></td>
<td><font color="Highlight">描述</font></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="LightYellow">
<td>
<%# DataBinder.Eval(Container.DataItem,"CategoryID") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"CategoryName") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"Description") %>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"CategoryID") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"CategoryName") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"Description") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
<asp:ImageButton CommandName="previous" ID="previous" ImageUrl=".\images\previous.gif" Runat="server" />
<asp:ImageButton CommandName="next" ID="next" ImageUrl=".\images\next.gif" Runat="server" />
</FooterTemplate>
</asp:Repeater></FONT>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
/**//// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Repeater Repeater1;
protected SqlConnection con = null;
protected string CON_STR="server=192.168.0.99;database=Northwind;user id=sa;password=jabby";
protected string SQL_QUERY="select * from Categories";
protected SqlDataAdapter da = null;
protected DataSet ds = null;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindData(0,4);
}
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Repeater1.ItemCommand += new System.Web.UI.WebControls.RepeaterCommandEventHandler(this.Repeater1_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void BindData(int start,int end)
{
try
{
con = new SqlConnection(CON_STR);
}
catch(SqlException sqlexp)
{
Response.Write("Connect to database Error! "+sqlexp.Message);
}
da = new SqlDataAdapter(SQL_QUERY,con);
ds = new DataSet();
try
{
da.Fill(ds,start,end,"Categories");
this.Repeater1.DataSource = ds;
this.Repeater1.DataBind();
}
catch(Exception exp)
{
Response.Write(exp.Message);
}
finally
{
con.Close();
}
}
private void Repeater1_ItemCommand(object sender,System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
if(e.CommandName.Equals("next"))
{
BindData(4,7);
}
else if(e.CommandName.Equals("previous"))
{
BindData(0,4);
}
}
}
}
此分页利用的是DataAdapter的Fill功能,但它提供的这种方式效率较低,因此只适用于少量数据,在大量数据情况下效率明显降低。 截图: 编号 名称 描述
1 Beverages Soft drinks, coffees, teas, beers, and ales
2 Condiments Sweet and savory sauces, relishes, spreads, and seasonings
3 Confections Desserts, candies, and sweet breads
4 Dairy Products Cheeses
编号 名称 描述
5 Grains/Cereals Breads, crackers, pasta, and cereal
6 Meat/Poultry Prepared meats
7 Produce Dried fruit and bean curd
8 Seafood Seaweed and fish
下一篇:Sucess On a Horse >>
相关文章:
- · 用asp编写文档搜索页面
- · ASP中使用SQL语句
- · 利用反射动态调用类成员
- · Asp.net组件设计浅论
- · 越过调试这道槛——ASP.NET无法调试问题剖析
- · 一段用ASP查看ASP文件源码的程序.
- · ASP显示在线人数
- · Asp.net多页面间保留状态
- · 简单ASP计数器
- · 使用 HttpContext.RewritePath 来配合 Server.Transfer/Execute
- · SQLSERVER扩展存储过程XP_CMDSHELL的简单应用
- · SQL Server 存储过程的分页
- · 经典的asp整理
- · Access中分组统计的实例
- · 一段分页程序实例代码!
- · 从asp到asp.net之快速转型
- · ASP升级程序
- · 利用WebClient类向服务器上载文件
- · .net中Web自定义控件编写的几个注意事项
- · 奇妙的.NET之Web程序中使用windows弹出框
- · webservice.htc无法传递中文数据的解决
- · 用反射调用别人的.NET程序里的类和方法
- · DataView如何绑定Web Service返回的主从表数据集
- · 在类中添加断言
- · UBB代码的实现(ASP)
- · 精确的判断网络是否可用
- · 调试SharePoint web part时, 如何可以多个人同时启动调试?
- · 关于编译器失败,错误代码为 128。的解决方案
- · 如何实现将用户上传的文件生成缩略图!
- · 链接提示文字的实现
- · Code Behind技术
- · 几个开源项目实体层实现方式比较
- · 上传图片并生成缩略图
- · ASP全程讲座
- · 在网页中添加天气预报
- · 鼠标下浮动的文字和时钟
- · 音乐城堡2004免费版
- · ASP汉字转拼音函数
