int
pageStart=0;
int
n=0;
int
pageSize=20;
在下一页按钮事件中定义
pageStart=n*20;
n += 1;
dataGrid1.DataSource=AdapterFillTable(pageStart,
pageSize,
SqlString);
在上一页按钮事件中定义中
pageStart=n*20;
n -= 1;
dataGrid1.DataSource=AdapterFillTable(pageStart,
pageSize,
SqlString);
首页按钮事件中定义中
pageStart=0;
dataGrid1.DataSource=AdapterFillTable(pageStart,
pageSize,
SqlString);
在末页按钮事件中定义中
pageStart=(n-1)*20;//这个n要计算页数也就是最大页数
dataGrid1.DataSource=AdapterFillTable(pageStart,
pageSize,
SqlString);
下面为分页方法:
public
static
DataTable AdapterFillTable(
int
pageStart,
int
pageSize,
string
SqlString)
{
SqlDataAdapter Adapter =
new
SqlDataAdapter();
DataTable Table =
new
DataTable();
using
(SqlConnection connetion =
new
SqlConnection(connectionString))
{
Adapter.SelectCommand =
new
SqlCommand(SqlString, connetion);
Adapter.Fill(pageStart, pageSize, Table);
return
Table;
}
}
这只简单的分页,只作为参考。