当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > AspNetPager与Socut.Data使用方法

ASP.NET
asp.net 动态生成表格
asp.net 程序优化精选
DataGridView自动调整行高和行宽
asp.net+js实现的ajax sugguest搜索提示效果
asp.net 将设有过期策略的项添加到缓存中
asp.net SqlDataAdapter对象使用札记
DataGrid 动态添加模板列 实现代码
asp.net 设置GridView的选中行
the sourcesafe database has been locked by the administrator之解决方法
asp.net 退出登陆(解决退出后点击浏览器后退问题仍然可回到页面问题)
Asp.Net HttpHandler 妙用
ASP.NET 保留文件夹详解
asp.net 中将表单提交到另一页 Code-Behind(代码和html在不同的页面)
SqlDataSource 链接Access 数据
asp.net GridView的删除对话框的两种方法
asp.net 按字节检查包含全半角的文字
asp.net String.IsNullOrEmpty 方法
asp.net System.Net.Mail 发送邮件
c# 读取文件内容存放到int数组 array.txt
asp.net Split分割字符串的方法

ASP.NET 中的 AspNetPager与Socut.Data使用方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-11   浏览: 96 ::
收藏到网摘: n/a

最近对AspNetPager与Socut.Data这两个控件产生了浓厚的兴趣,这两个控件配合可以减轻很多程序员编写代码的压力。ASpNetPager为分页控件,而Socut.Data为数据操作控件,ACCESS,MSSQL都可以。 连接数据库只要在web.config中:
<appSettings>
<add key="SocutDataLink" value="data.mdb" />
</appSettings>
下面我记下每个小例子的主要代码过程:
1、ACCESS+GridView+数据读取+简单分页例子。

aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!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>AspNetPager与Socut.Data使用</title>
<style type="text/css">
body{font:12px tahoma;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvwTest" runat="server" AutoGenerateColumns="false">
<columns>
<asp:BoundField DataField="Id" HeaderText="ID" HeaderStyle-Width="50" />
<asp:BoundField DataField="username" HeaderText="姓名" HeaderStyle-Width="200" />
</columns>
</asp:GridView>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged" PageSize="10" UrlPaging="True">
</webdiyer:AspNetPager>
</div>
</form>
</body>
</html>
cs文件:
protected void Page_Load(object sender, EventArgs e)
{
AspNetPager1.RecordCount = (int)Socut.Data.ExecuteScalar("select count(*) from admin");
if (!Page.IsPostBack)
{
datainit();
}
}
private void datainit()
{
DataSet ds = Socut.Data.ExecuteDataSet("select * from admin", AspNetPager1.PageSize*(AspNetPager1.CurrentPageIndex - 1),AspNetPager1.PageSize);
gvwTest.DataSource = ds;
gvwTest.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
datainit();
}
先引入控件,然后写小部分代码就能实现简单分页效果,方便快效,是我决定在以后项目中采用它的原因。而它的分页样式可以十分灵活的控制,比如我改成如下: