存储过程:

GetProductsCount1:

GetProductsByPage:


CREATE PROCEDURE GetProductsByPage
@PageNumber int,
@PageSize int
AS
declare @sql nvarchar()
set @sql ='select top '+ Convert(varchar, @PageSize) +' * from test where id not in (select top '+ Convert(varchar, (@PageNumber -) * @PageSize) +' id from test)'
exec sp_executesql @sql
GO

前台代码:

代码

view plaincopy to clipboardprint?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2"%>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer"%>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Namespace="System.Web.UI" TagPrefix="asp"%>

<!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>

<mce:style type="text/css"><!--

.lbtnstyle{
font-size: 12px; color: black; text-
decoration: none;color:red;
}
.anpager .cpb {background:#1F3A87 none repeat scroll ;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px ;padding:4px 5px ;font-
size:12px}
.anpager a {background:#FFFFFF none repeat scroll ;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px ;padding:4px 5px ;text-decoration:none;font-
size:12px}
.anpager a:hover{background:#1F3A87 none repeat scroll
;border:1px solid #1F3A87;color:#FFFFFF;}

--></mce:style><style type="text/css" mce_bogus=""> .lbtnstyle{
font-size: 12px; color: black; text-
decoration: none;color:red;
}
.anpager .cpb {background:#1F3A87 none repeat scroll ;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px ;padding:4px 5px ;font-
size:12px}
.anpager a {background:#FFFFFF none repeat scroll ;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px ;padding:4px 5px ;text-decoration:none;font-
size:12px}
.anpager a:hover{background:#1F3A87 none repeat scroll
;border:1px solid #1F3A87;color:#FFFFFF;}
</style>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

<table>

<tr>

<td width="">

<asp:TextBox ID="txtname" runat="server"></asp:TextBox>

</td>

<td width="">

<asp:Button ID="btninsert" runat="server" Text="添加行"/>

</td>

</tr>

<tr>

<td colspan="">

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="450px" CellPadding="" ForeColor="#333333" GridLines="None" style="font-size:12px" mce_style="font-size:12px" OnRowDataBound="GridView1_RowDataBound1">

<Columns>

<asp:TemplateField>

<HeaderTemplate>

ID
</HeaderTemplate>

<EditItemTemplate><asp:TextBox ID="txtid" runat="server" Text='<%#Eval("id") %>' Enabled="false"></asp:TextBox></EditItemTemplate>

<ItemTemplate><asp:Label ID="labid" runat="server" Text='<%# Eval("id") %>'></asp:Label></ItemTemplate>

<ControlStyle Width="170px"/>

</asp:TemplateField>

<asp:TemplateField>

<HeaderTemplate>

名称
</HeaderTemplate>

<EditItemTemplate><asp:TextBox ID="txtname" runat="server" Text='<%#Eval("name") %>'></asp:TextBox></EditItemTemplate>

<ItemTemplate><asp:Label ID="labname" runat="server" Text='<%# Eval("name") %>'></asp:Label></ItemTemplate>

<ControlStyle Width="170px"/>

</asp:TemplateField>

<asp:TemplateField>

<EditItemTemplate>

<asp:LinkButton ID="lbtnupdt" runat="server" CommandName="Update" Text="更新"class="lbtnstyle" OnClientClick="return confirm('确定更新?');"></asp:LinkButton>

<asp:LinkButton ID="lbtncan" runat="server" CommandName="Cancel" Text="取消"class="lbtnstyle"></asp:LinkButton>

</EditItemTemplate>

<ItemTemplate>

<asp:LinkButton ID="lbtnedit" CommandName="Edit" runat="server" Text="编辑"class="lbtnstyle"></asp:LinkButton>

<asp:LinkButton ID="lbtndel" CommandName="Delete" runat="server" Text="删除"class="lbtnstyle" OnClientClick="return confirm('确定删除?');"></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

</Columns>

<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>

<RowStyle BackColor="#EFF3FB"/>

<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center"/>

<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333"/>

<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>

<EditRowStyle BackColor="#2461BF"/>

<AlternatingRowStyle BackColor="White"/>

</asp:GridView>

</td>

</tr>

<tr>

<td colspan="" align="right">

<webdiyer:AspNetPager ID="AspNetPager1" runat="server" CssClass="anpager" CurrentPageButtonClass="cpb" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页">

</webdiyer:AspNetPager>

</td>

</tr>

</table>

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</body>

</html>

后台代码:

代码

private SqlConnection con;
int currentPageNumber;//当前页号

int pageSize =;//每页显示记录条数
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!
IsPostBack)
{
currentPageNumber =
;
ViewState["currentPageNumber"] =
currentPageNumber;
getbind();
}
//注册事件

GridView1.RowDeleting +=new GridViewDeleteEventHandler(GridView1_RowDeleting);
GridView1.RowEditing +=new
GridViewEditEventHandler(GridView1_RowEditing);
GridView1.RowUpdating +=new
GridViewUpdateEventHandler(GridView1_RowUpdating);
GridView1.RowCancelingEdit +=new
GridViewCancelEditEventHandler(GridView1_RowCancelingEdit);
btninsert.Click +=new
EventHandler(btninsert_Click);
AspNetPager1.PageChanged +=new
EventHandler(AspNetPager1_PageChanged);

}
//分页事件

void AspNetPager1_PageChanged(object sender, EventArgs e)
{
currentPageNumber=
AspNetPager1.CurrentPageIndex;
ViewState["currentPageNumber"] =
currentPageNumber;
getbind();
}
//添加一行数据事件

void btninsert_Click(object sender, EventArgs e)
{
string sql ="insert into test (name)values('"+ txtname.Text +"')"
;
con =new SqlConnection("Server=.;DataBase=JobWanted Apartment;Uid=sa;pwd="
);
SqlCommand cmd =new
SqlCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
getbind();
}
//取消GridView编辑

void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{

GridView1.EditIndex =-;
getbind();
}
//GridView修改事件

void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sql ="update test set name='"+ (((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtname")).Text) +"' where id='"+Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtid")).Text)+"' "
;
con =new SqlConnection("Server=.;DataBase=JobWanted Apartment;Uid=sa;pwd="
);
SqlCommand cmd =new
SqlCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
GridView1.EditIndex =-
;
getbind();
}
//GridView编辑事件

void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex =
e.NewEditIndex;
getbind();
}
//GridView删除行事件

void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sql ="delete from test where id='"+ Convert.ToInt32(((Label)GridView1.Rows[e.RowIndex].FindControl("labid")).Text) +"'"
;
con =new SqlConnection("Server=.;DataBase=JobWanted Apartment;Uid=sa;pwd="
);
SqlCommand cmd =new
SqlCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
getbind();
}
//GridView数据绑定

privatevoid getbind()
{
currentPageNumber =Convert.ToInt32( ViewState["currentPageNumber"
]);
con =new SqlConnection("Server=.;DataBase=JobWanted Apartment;Uid=sa;pwd="
);
SqlCommand cmd =new SqlCommand("GetProductsCount1"
, con);
cmd.CommandType =
CommandType.StoredProcedure;
SqlCommand cmd1 =new SqlCommand("GetProductsByPage"
, con);
cmd1.CommandType=
CommandType.StoredProcedure;
cmd1.Parameters.Add("@PageNumber", SqlDbType.Int, ).Value =
currentPageNumber;
cmd1.Parameters.Add("@PageSize", SqlDbType.Int, ).Value =
pageSize;
con.Open();
DataTable dt =new
DataTable();
SqlDataAdapter adapter =new
SqlDataAdapter(cmd1);
adapter.Fill(dt);
//AspNetPager1.PageSize = 10;//设置每页显示的行数

AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();//得出总的记录条数
AspNetPager1.CurrentPageIndex = currentPageNumber;
GridView1.DataSource =
dt;
GridView1.DataBind();
}
//GridView高亮行显示

protectedvoid GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType ==
DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor,this.style.backgroundColor='#C7DEF3'"
);
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"
);
}
}

转载:http://blog.csdn.net/weng2961389/archive/2010/03/04/5346063.aspx

CREATE PROCEDURE GetProductsCount1 AS
select count(*) from test
GO

Gridview各种功能+AspNetPager+Ajax实现无刷新存储过程分页 (留着用)的更多相关文章

  1. jQuery+php+ajax实现无刷新上传文件功能

    jQuery+php+ajax实现无刷新上传文件功能,还带有上传进度条动画效果,支持图片.视频等大文件上传. js代码 <script type='text/javascript' src='j ...

  2. 使用ajax实现无刷新改变页面内容

    如何使用ajax实现无刷新改变页面内容(也就是ajax异步请求刷新页面),下面通过一个小demo说明一下,前端页面代码如下所示 1 <%@ Page Language="C#" ...

  3. jsp+ajax实现无刷新

    jsp+ajax实现无刷新,鼠标离开文本框即验证用户名 jsp+ajax实现无刷新,鼠标离开文本框即验证用户名(本功能多用于注册) input.jsp(表单提交页面): %@ page content ...

  4. window.history.pushState与ajax实现无刷新更新页面url

    ajax能无刷新更新数据,但是不能更新url HTML5的新API: window.history.pushState, window.history.replaceState 用户操作history ...

  5. Ajax 实现无刷新分页

    Ajax 实现无刷新分页

  6. Ajax 实现无刷新页面

    注意:如本文所用,在前面的文章库的数目可以在源代码中找到,我将指示在文本,其中链路,为了缩短制品的长度,阅读由此带来的不便.乞求被原谅. 评论文章 Ajax 实现无刷新页面.其原理.代码库.代码. 这 ...

  7. PHP+Ajax+plupload无刷新上传头像代码

    很简单的一款PHP+Ajax+plupload无刷新上传头像代码,兼容性很好,可以直接拿来用.你可以自定义各种类型的文件.本实例中只能上传"jpg", "png" ...

  8. angular -- 无刷新做分页

    无刷新做分页参考地址: http://www.jq22.com/demo/angular201707111100/ 示例代码: <!DOCTYPE html> <html lang= ...

  9. jQuery AJAX 网页无刷新上传示例

    新年礼,提供简单.易套用的 jQuery AJAX 上传示例及代码下载.后台对文件的上传及检查,以 C#/.NET Handler 处理 (可视需要改写成 Java 或 PHP). 有时做一个网站项目 ...

随机推荐

  1. Android开发(二)——自定义圆形控件的使用CircleImageView

    CircleImageView,a fast circular ImageView perfect for profile images. 主要的类CircleImageView: package d ...

  2. pymongo 使用测试

    >>> import pymongo >>> uri = "mongodb://recall:123456@oceanic.mongohq.com:100 ...

  3. Python如何下载文件

    转载自:http://www.codecho.com/how-to-download-a-file-in-python/ 利用程序自己编写下载文件挺有意思的.Python中最流行的方法就是通过Http ...

  4. C#学习笔记(28)——匿名委托和Lambda表达式

    说明(2017-11-21 18:51:32): 1. 例子为求1~100的和,答案应该是5050(小学学算盘的时候,我爹就让我算,从1拨到100是多少呀?当时的我年幼无知,还不知道高斯小时候的故事, ...

  5. iOS录制视频

    随着每一代 iPhone 处理能力和相机硬件配置的提高,使用它来捕获视频也变得更加有意思.它们小巧,轻便,低调,而且与专业摄像机之间的差距已经变得非常小,小到在某些情况下,iPhone 可以真正替代它 ...

  6. .net将枚举转成List

    using System; using System.Collections.Generic; using System.ComponentModel; namespace zifar.SgmhWeb ...

  7. [转]启动Tomcat提示:指定的服务未安装

    原文地址:http://blog.csdn.net/yilip/article/details/8066246 新下载的Tomcat7.0 解压缩完了运行tomcat7.exe屏幕一闪就没了 运行to ...

  8. RDD、DataFrame和DataSet

    简述 RDD.DataFrame和DataSet是容易产生混淆的概念,必须对其相互之间对比,才可以知道其中异同:DataFrame多了数据的结构信息,即schema.RDD是分布式的 Java对象的集 ...

  9. anconda使用---使用conda管理python环境

    一.动机 最近打算折腾vn.py,但只有py27版本的,因为一向习惯使用最新稳定版的,所以不得不装py27的环境,不得不说 Python的全局锁真的很烦. 身为懒癌患者,必然使用全功能的anacond ...

  10. [Python学习]Python学习资料汇总

    Python其实很简单,入门+提高看一些简单的教程就能学会,这里列出一些比较好的资料: 廖雪峰博客 https://www.liaoxuefeng.com/wiki/0014316089557264a ...