zoukankan
html css js c++ java
在DataGrid中实现分页
用过ASP的朋友也许对起分页感到头大,但在ASP。NET中其自动分页功能便让您能得心应手。这是前台代码:
后台代码如下:
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;
using
System.Configuration;
namespace
mynew
{
/**/
///
<summary>
///
WebForm1 的摘要说明。
///
</summary>
public
class
WebForm1 : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.LinkButton LinkButton1;
protected
System.Web.UI.WebControls.LinkButton LinkButton2;
protected
System.Web.UI.WebControls.LinkButton LinkButton3;
protected
System.Web.UI.WebControls.LinkButton LinkButton4;
protected
System.Web.UI.WebControls.Label lblCurrentIndex;
protected
System.Web.UI.WebControls.Label lblPageCount;
protected
System.Web.UI.WebControls.DataGrid MyDataGrid;
private
void
Page_Load(
object
sender, System.EventArgs e)
{
SqlConnection conn
=
new
SqlConnection(ConfigurationSettings.AppSettings[
"
dsn
"
]);
conn.Open();
SqlDataAdapter myAdapter
=
new
SqlDataAdapter();
myAdapter.SelectCommand
=
new
SqlCommand(
"
select CategoryID,CategoryName from Categories
"
,conn);
//
myAdapter.SelectCommand.CommandType=CommandType.StoredProcedure;
DataSet ds
=
new
DataSet();
myAdapter.Fill(ds,
"
Categories
"
);
MyDataGrid.DataSource
=
ds;
MyDataGrid.DataBind();
lblCurrentIndex.Text
=
"
第
"
+
((Int32)MyDataGrid.CurrentPageIndex
+
1
)
+
"
页
"
;
lblPageCount.Text
=
"
/共
"
+
MyDataGrid.PageCount
+
"
页
"
;
conn.Close();
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.LinkButton1.Click
+=
new
System.EventHandler(
this
.PagerButton_Click);
this
.LinkButton2.Click
+=
new
System.EventHandler(
this
.PagerButton_Click);
this
.LinkButton3.Click
+=
new
System.EventHandler(
this
.PagerButton_Click);
this
.LinkButton4.Click
+=
new
System.EventHandler(
this
.PagerButton_Click);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
private
void
PagerButton_Click(
object
sender, System.EventArgs e)
{
string
arg
=
((LinkButton)sender).CommandArgument;
//
获取LinkButton的参数值
switch
(arg)
{
case
(
"
next
"
):
if
(MyDataGrid.CurrentPageIndex
<
(MyDataGrid.PageCount
-
1
))
MyDataGrid.CurrentPageIndex
++
;
break
;
case
(
"
prev
"
):
if
(MyDataGrid.CurrentPageIndex
>
0
)
MyDataGrid.CurrentPageIndex
--
;
break
;
case
(
"
first
"
):
MyDataGrid.CurrentPageIndex
=
0
;
break
;
case
(
"
last
"
):
MyDataGrid.CurrentPageIndex
=
MyDataGrid.PageCount
-
1
;
break
;
}
MyDataGrid.DataBind();
}
}
}
就怎么如次 easy 一个简单的分页便实现了。
查看全文
相关阅读:
Agile EC 301 Installing and Configuring EC Web Connector
Agile EC 301 BOM Publishing
Agile PLM EC Administration Preference
MySQL 5.6.10 Optimizer Limitations: Index Condition Pushdown
mysql 启动异常失败 Starting MySQL..The server quit without updating PID file
Sysbench 进行磁盘IO测试的输出结果解读
分析 tuningprimer.sh 源码
【Windows内核原理与实现】读书笔记(三)
【翻译】深入解析Windows操作系统(第五版)第一章
【WindowsDDK】内核字符串操作蓝屏的一个解决办法
原文地址:https://www.cnblogs.com/long/p/79190.html
最新文章
Where does Visual Studio look for C++ Header files?
使用python检测windows操作系统架构(x86\x64)
GNU
【转】mysql的dump命令
linux下安装lighttpd
Vim工作模式、Vim基础应用、高级应用
PHP容易出错在十四个问题
删除所有ecshop版权和logo
PHP的strtok()函数的优点详解
系统架构师学习笔记_第十五章_连载
热门文章
MySQL数据库中delimiter的作用概述
系统架构师学习笔记_第十三章(下)_连载
系统架构师学习笔记_第十六章_连载
Agile PLM EC 301 Mapping Editor
Agile EC 301 Save Design Structures
Agile EC 301 SW Connector Instllation
Agile PLM EC 301 Workspace CAD working directory vs. EC Workspaces
EC MCAD Connector 3010 AdminGuide2
Agile PLM Server Class Administration
Agile EC 数据存储结构
Copyright © 2011-2022 走看看