Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
I am using <asp:Table> control. and displaying data dynamically. but i want to give Pageing in this table.. then Please suggest me how to give pageing in asp table.



Thanks

modified on Thursday, July 17, 2008 6:35 AM
Posted

1 solution

raushan_9 wrote:
I am using <asp:table xmlns:asp="#unknown"> control. and displaying data dynamically. but i want to give Pageing in this table.. then Please suggest me how to give pageing in asp table.

Follow these steps

Step 1: Add one column field in DataTable
Retrieve Data from database and add one column in this datatable using asp.net and increament it by 1.
Suppose you have 100 records so that field values should be 1 to 100

Step 2:Set property
Create three properties CurrentPage, PageSize and PageCount
PageCount is total number of record
PageSize to display number of record on page
CurrentPage is PageIndex

Set these three properties value on page load event after retrieving data from database and add column field in this datatable

Step 3:Take two link Button
Take Previous and Next Link button

Step 4:Get record from DataTable and bind asp table
Before calling this,you must add one column field in datatable so you can get number of record
Suppose,You have 100 record and you have set pagesize 10
first time CurrentPage should be 1
You can get 1 to 10 record from datatable by using select method of datatable
Suppose you add one column with ID,then your code looks like this

you can get "to" to "from" value by this

int t=(CurrentPage-1)*PageSize; // (1-1)*10=0<br />int f=CurrentPage*PageSize+1; 1*10+1=11<br />DataRow[] dRow=dataTable.Select("ID>"+t+" and ID<"+f);// dataTable is your DataTable object

the Above line will return you first ten record,you can bind your asp table with these 10 records

step 5: On Next Link Button event
On Next Button event, increament CurrentPage
Suppose at first time you click on Next Button,CurrentPage increament by 1.
now currentPage is 2

calculate again "to" to "from" value

int t=(CurrentPage-1)*PageSize; // (2-1)*10=10<br />int f=CurrentPage*PageSize+1; 2*10+1=21<br />DataRow[] dRow=dataTable.Select("ID>"+t+" and ID<"+f);//dataTable is your DataTable object


you can loop through DataRow array and get value from it and bind your asp table

the Above line will return you second 11 to 20 records

Now check here

if PageCount/PageSize is less then currentpage then disable next link button
Suppose you have 99 records your current page 10 then it display 90 to 99 records.Next you have not record so it should be disbled.


Step 6:On previous link button
at first time, when CurrentPage is 1,Privous button link should be disabled.
Same thing here.you have to decrease CurrentPage and process will be same

Note : Store current page in ViewState so you can get it from it other wise it will set default.

I hope this will help you
best of luck

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900