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 DataTableRetrieve 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 propertyCreate 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 ButtonTake Previous and Next Link button
Step 4:Get record from DataTable and bind asp tableBefore 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;
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 eventOn 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;
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 buttonat 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