If you are using datagrid to display the records then Set the Paging & CustomPaging property of the DataGrid to true and pagesize to 20.
See the sample below:
private void Page_Load(object sender, System.EventArgs e)
{ // Put user code to initialize the page here
if(!IsPostBack){
BindGrid(0,DataGrid1.PageSize);
}
}
private void BindGrid(int st,int nt){
string sqlconn;
string strSql;
sqlconn=ConfigurationSettings.AppSettings["conn"];
SqlConnection conn=new SqlConnection(sqlconn);
strSql="select job_id,job_desc,min_lvl,max_lvl from jobs where job_id>="+st+" and job_id<="+nt+"";
SqlDataAdapter strAdap=new SqlDataAdapter(strSql,conn);
DataSet ds=new DataSet();
strAdap.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.VirtualItemCount=100;
DataGrid1.DataBind();
}
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.DataGrid1_PageIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid((e.NewPageIndex *DataGrid1.PageSize)+1,(e.NewPageIndex* DataGrid1.PageSize)+DataGrid1.PageSize);
}
Here BindGrid() function is used to bind the data's to the datagrid and VirtualItemCount property allows the control to determine the total number of pages needed to display every item in the DataGrid control.
|