473,748 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to implement custom paging in asp.net?

304 Contributor
Hi,
I would like to know as to how one could implement custom paging in asp.net.
Any insight or reference materials or articles that you could point me to would be greatly appreciated.
Thanks,
Gomzi.
Jun 4 '07 #1
11 5113
Frinavale
9,735 Recognized Expert Moderator Expert
Hi,
I would like to know as to how one could implement custom paging in asp.net.
Any insight or reference materials or articles that you could point me to would be greatly appreciated.
Thanks,
Gomzi.
Custom paging?
Custom movement between pages?
Custom paging for a GridView object?

I don't understand.

-Frinny
Jun 4 '07 #2
gomzi
304 Contributor
Custom paging?
Custom movement between pages?
Custom paging for a GridView object?

I don't understand.

-Frinny
Hi Frinny,
I would like to implement custom paging for a gridview.

Any idea as to how I could achieve that ?

Thanks,
Gomzi.
Jun 4 '07 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Hi Frinny,
I would like to implement custom paging for a gridview.

Any idea as to how I could achieve that ?

Thanks,
Gomzi.
Have you tried implementing the function that handles the PageIndexChange d event for the GridView?
Jun 4 '07 #4
gomzi
304 Contributor
Have you tried implementing the function that handles the PageIndexChange d event for the GridView?
Till now I used to do paging wherein i got the whole data and stored it in a dataset.
But now I felt the need for custom paging.
So, I decided to code one using the below mechanism.

A gridview for displaying the data.
Two link buttons for previous and next.
And then retrieving 10 rows depending on the page number which I am getting through previous and next.
But the point where I am stuck is that I am currently unable to retrieve the records depending on the page number.
i.e. how do I retrieve records depending on the page number?

I am using mysql as the database.
Jun 4 '07 #5
Frinavale
9,735 Recognized Expert Moderator Expert
Till now I used to do paging wherein i got the whole data and stored it in a dataset.
But now I felt the need for custom paging.
So, I decided to code one using the below mechanism.

A gridview for displaying the data.
Two link buttons for previous and next.
And then retrieving 10 rows depending on the page number which I am getting through previous and next.
But the point where I am stuck is that I am currently unable to retrieve the records depending on the page number.
i.e. how do I retrieve records depending on the page number?

I am using mysql as the database.
I don't understand why you would go to all this trouble when the GridView does the paging etc. for you. There's no reason to deviate from something that is so standard.

I strongly recommend using the paging supplied by your GridView.
It will save you a lot of time and headache.

Don't re-invent the wheel
-Frinny
Jun 4 '07 #6
gomzi
304 Contributor
I don't understand why you would go to all this trouble when the GridView does the paging etc. for you. There's no reason to deviate from something that is so standard.

I strongly recommend using the paging supplied by your GridView.
It will save you a lot of time and headache.

Don't re-invent the wheel
-Frinny
Ya Frinny, thats true " Don't re-invent the wheel ".

But I guess, its already been re-invented. It's just that I am unaware of it. :)

Also, why I am trying to do such a thing is because, my database has a lot of records, and if everytime I bind all the records to the gridview i.e. for every page request, then the response will be extremely slow in comparison to one wherein one binds only the necessary records(dependi ng on the page requested by the user).
Jun 4 '07 #7
Frinavale
9,735 Recognized Expert Moderator Expert
Ya Frinny, thats true " Don't re-invent the wheel ".

But I guess, its already been re-invented. It's just that I am unaware of it. :)

Also, why I am trying to do such a thing is because, my database has a lot of records, and if everytime I bind all the records to the gridview i.e. for every page request, then the response will be extremely slow in comparison to one wherein one binds only the necessary records(dependi ng on the page requested by the user).
Hmmm, I see your problem.
I'm not sure how to help you there.
Hopefully someone else will help solve the problem with the slowness.

If not, post a new question asking how to maximize the response time during paging using a GridView.

Sorry I couldn't be more helpful,

-Frinny
Jun 4 '07 #8
gomzi
304 Contributor
Hmmm, I see your problem.
I'm not sure how to help you there.
Hopefully someone else will help solve the problem with the slowness.

If not, post a new question asking how to maximize the response time during paging using a GridView.

Sorry I couldn't be more helpful,

-Frinny
No probs. Will post the question now.

Thanks a lot for the interest anyway.
Gomzi.
Jun 4 '07 #9
Vijeybabu
2 New Member
Till now I used to do paging wherein i got the whole data and stored it in a dataset.
But now I felt the need for custom paging.
So, I decided to code one using the below mechanism.

A gridview for displaying the data.
Two link buttons for previous and next.
And then retrieving 10 rows depending on the page number which I am getting through previous and next.
But the point where I am stuck is that I am currently unable to retrieve the records depending on the page number.
i.e. how do I retrieve records depending on the page number?

I am using mysql as the database.

In this Example i have used Cache variable to hold the DataView Object in Cache Memory.
Why..?
I'm going to access BindGrid() Method many time So.. why should i go for server said again and again. So to avoid that i'm using Cache "Cache["MemberData "] = dvue;" for other Caches you can use Session Or ViewState also.
Then you have asked " retrieving 10 rows depending on the page number "
To achive this " dvue.RowFilter =....." is used.
Expand|Select|Wrap|Line Numbers
  1.     int TotalNoRows; (Globle Variable)
  2.     int NextPage;      (Globle Variable)
  3.     DataView dvue;   (Globle Variable)
  4.  
  5.     protected void Page_Load(object sender, EventArgs e)
  6.     {
  7.         if (!IsPostBack)
  8.         {
  9.             Cache["PageCount"] = 1;
  10.             int Loadpage = (int)Cache["PageCount"];
  11.             BindGrid(Loadpage);
  12.             btnPrev.Enabled = false;
  13.         }
  14.         int PgNo = Convert.ToInt32(Request.QueryString["pageno"]);
  15.         if (PgNo > 1)
  16.         {
  17.             if (!IsPostBack)
  18.             {
  19.                 btnPrev.Enabled = true;
  20.                 BindGrid(PgNo);
  21.             }
  22.         }
  23.     }    
  24.  
  25.     protected void btnNext_Click(object sender, EventArgs e)
  26.     {
  27.         btnPrev.Enabled = true;
  28.         //-----------------
  29.         NextPage = 1 + (int)Cache["PageCount"];
  30.         BindGrid(NextPage);
  31.     }
  32.  
  33.     protected void btnPrev_Click(object sender, EventArgs e)
  34.     {
  35.         btnNext.Enabled = true;
  36.         btnNext.Text = "Next";
  37.  
  38.         //--------------
  39.  
  40.         NextPage = (int)Cache["PageCount"] - 1;
  41.         BindGrid(NextPage);
  42.         if (NextPage == 1)
  43.             btnPrev.Enabled = false;
  44.     }
  45.  
  46.     private void BindGrid(int PageNo)
  47.     {
  48.         dvue = (DataView)Cache["MemberData"];
  49.         if (dvue == null)
  50.         {
  51.             string strSQL = "SELECT EmployeeID,FirstName,LastName FROM Employees";
  52.             SqlDataAdapter da = new SqlDataAdapter(strSQL, net.webindia.Conn_Open());
  53.  
  54.             DataSet ds = new DataSet();
  55.             DataTable tbl = ds.Tables.Add("BasicInformation");
  56.  
  57.             DataColumn col = tbl.Columns.Add("RowID", typeof(int));
  58.             col.AutoIncrement = true;
  59.             col.AutoIncrementSeed = 1;
  60.             col.AutoIncrementStep = 1;
  61.  
  62.             da.Fill(ds, "BasicInformation");
  63.             dvue = new DataView(tbl);
  64.  
  65.             Cache["MemberData"] = dvue;
  66.             Response.Write("Data Loaded from the Database at: " + DateTime.Now.ToShortTimeString());
  67.  
  68.             TotalNoRows = ds.Tables[0].Rows.Count;
  69.             Cache["TotalNoRows"] = TotalNoRows;
  70.         }
  71.         //Response.Write("Total Records: "+ Cache["TotalNoRows"].ToString());
  72.  
  73.         int intPageSize = 10;
  74.         int intPageNum = PageNo;
  75.         Cache["PageCount"] = PageNo;
  76.         //For all the Popup page back link we are passing the pageno.
  77.  
  78.  
  79.         if (((intPageNum - 1) * intPageSize) <= (int)Cache["TotalNoRows"])
  80.             dvue.RowFilter = "RowID > " + (intPageNum - 1) * intPageSize + " and RowID <= " + intPageNum * 
  81.  
  82. intPageSize;
  83.         else
  84.         {
  85.             //To find the Last Record and to disable the Next button.
  86.             btnNext.Enabled = false;
  87.             btnNext.Text = "End";
  88.         }
  89.  
  90.         //DataGrid binding using DataView.
  91.         dg1.DataSource = dvue;
  92.         dg1.DataBind();
  93.  
  94.         //To find the Last Record and to disable the Next button.
  95.         if (dg1.Items.Count < 10)
  96.         {
  97.             btnNext.Enabled = false;
  98.             btnNext.Text = "End";
  99.         }
  100.     }
  101.  
If you bind the DataSet directly (with all records) to the DataGrid Or GridView performance will go down when no of records are more.
But in this method we are binding 10 records each time so performance is high.
(Faster)
Jun 5 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1627
by: Stephen | last post by:
This is a real brain-teaser and i'd really appreciate it if someone can try and understand what im trying to do and give me a few pointers or ideas to help me work out my problem. Im basically using the example of CUSTOM PAGING on a DataGrid on this page: http://www.dotnetjunkies.com/Tutorial/EA868776-D71E-448A-BC23-B64B871F967F.dcik and im trying to add extra functionality in the DataGrid Paging - Custom Paging example. I'm able to get...
0
1078
by: akn | last post by:
Hi, I am trying to do custom paging on my datagrid. Most of the examples that i found are with next previous. I need to use page numbers such that when a user clicks on page 2 then he is taken to page 2 and while on page 2 that link becomes disabled but all the other page numbers 1,3,4,5, are enabled. How can i use page numbers with custom paging?
2
3488
by: Maziar Aflatoun | last post by:
Hi, I'm having problems with Custom Paging. Most of the articles out there show that the custom paging is done as the following article. http://authors.aspalliance.com/aspxtreme/sys/Web/UI/WebControls/DataGridClassAllowCustomPaging.aspx (Check the example 'Custom Paging with AutoIncrement Data Model'). However, the assumption here is that the rows are all there 1,2,3,4,5,6,7,8 but that's not the case with many database tables. You can...
2
2222
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
0
1106
by: asad | last post by:
Hello, i want to do Custom paging i'm using MS Access Database when i'm using SQL SERVER Database Custom paging work ok but when i'm using MS Access Database it does not work pls tell me how can i do custom paging with MS Access Database pls tell me. Thanks
1
1643
by: thechaosengine | last post by:
Hi all, Can somebody tell me if the built in paging support for the datagrid works when using a custom collection and a custom business object as the data. I was well pleased when I found that I could bind a custom class to the datagrid. Now however, I'm worried that paging is buggered because I'm using custom classes. Should this be possible and if not, would custom paging work?
0
1157
by: Wiktor Zychla [C# MVP] | last post by:
Hello, just two sad thoughts on GridView's custom paging support, the first one rather general and second one rather specific. First one: I really miss the DataGrid custom paging support with AllowCustomPaging and VirtualCount. The new declarative model with ObjectDataSource is much worse! - the amount of "words" you have to type is comparable (few methods in C# vs declarative binding with ObjectDataSource), however the static typing...
3
4981
by: Sachin | last post by:
Hi All, I am using ASP.NET 2.0 Tree control to display hierarachical data. However because of the size of the data, tree takes ages to load on the browser. For that reason, I want to build custom paging solution similar to custom paging in datagrid/gridview...
0
1561
by: Roy | last post by:
Hey all, I must be losing my touch. I have made many pages in the 1.1 framework that utilize custom bidirectional paging in datagrids. We've converted over to 2.0 and I've been trying to use the built-in functionality of gridviews and objectdatasource's to accomplish the same thing (w/o resorting to the 1.1 methodology). I discovered two very nice and comprehensive articles concerning this: Custom Paging in ASP.NET 2.0 with SQL Server...
0
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9326
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.