c#分页Pagination与数据库视图DataGridView的连接方法
1、未连接分页,数据库视图显示数据库
SqlHelper sqlhelper = new SqlHelper();
public void InitMain()
{
string sql = "select * from t_dpxx";
DataTable dt = sqlhelper.ExecuteReaderEx(sql);
Dgv_Data.DataSource = dt;
}
2、连接分页
SqlHelper sqlhelper = new SqlHelper();
public void InitMain()
{
string sql = "select * from t_dpxx";
DataTable dt = sqlhelper.ExecuteReaderEx(sql);
P_Data.DataSource = dt;//这里注意要绑定在分页栏上!
P_Data.ActivePage = 1;
}
private void P_Data_PageChanged(object sender, object pagingSource, int pageIndex, int count)
{
Dgv_Data.DataSource = pagingSource;
}
引用P_Data_PageChanged方法:
点击分页Pagination添加事件即可完成绑定