45fan.com - 路饭网

搜索: 您的位置主页 > 电脑频道 > 电脑教程 > 阅读资讯:自定义分页的方法技巧

自定义分页的方法技巧

2016-08-30 10:53:39 来源:www.45fan.com 【

自定义分页的方法技巧

privateOleDbConnectioncon=newOleDbConnection();

privatevoidPage_Load(objectsender,System.EventArgse)
{
OpenDataBase();
BindDataGrid();
}


privatevoidOpenDataBase()
{
con.ConnectionString
="Provider=SqlOleDb;WorkStationID=127.0.0.1;InitialCatalog=Northwind;UserID=sa;PassWord=;ConnectTimeOut=30;PacketSize=1024;PersistSecurityInfo=false";
con.Open();
}


publicvoidBindDataGrid()
{
OleDbConnectionmyConnection
=con;
DataSetds
=newDataSet();
OleDbDataAdapteradapter
=newOleDbDataAdapter("SelectLastName,FirstName,AddressFromEmployees",myConnection);
adapter.Fill(ds,
"Document");
dgdNorthwind.DataSource
=ds.Tables["Document"].DefaultView;
dgdNorthwind.DataBind();
ShowState();
}


privatevoidShowState()
{
lblPageCount.Text
="总共"+dgdNorthwind.PageCount+"";
lblCurrentPageIndex.Text
=""+(dgdNorthwind.CurrentPageIndex+1).ToString()+"";
}


privatevoiddgdNorthwind_PageIndexChanged(objectsource,System.Web.UI.WebControls.DataGridPageChangedEventArgse)
{
dgdNorthwind.CurrentPageIndex
=e.NewPageIndex;
BindDataGrid();
}


privatevoidClickButton(objectsender,EventArgse)
{

stringarg=((LinkButton)sender).CommandArgument.ToString();

switch(arg)
{

case"Next":
if(dgdNorthwind.CurrentPageIndex<(dgdNorthwind.PageCount-1))
{
dgdNorthwind.CurrentPageIndex
+=1;
}

break;
case"Prev":
if(dgdNorthwind.CurrentPageIndex>0)
{
dgdNorthwind.CurrentPageIndex
-=1;
}

break;
case"Last":
dgdNorthwind.CurrentPageIndex
=dgdNorthwind.PageCount-1;
break;
default:
dgdNorthwind.CurrentPageIndex
=0;
break;
}

BindDataGrid();
}
 

本文地址:http://www.45fan.com/dnjc/69667.html
Tags: newOleDbConnection
编辑:路饭网
相关文章列表
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部