473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to implement custom paging in asp.net?

304 100+
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 5093
Frinavale
9,735 Expert Mod 8TB
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 100+
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 Expert Mod 8TB
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 PageIndexChanged event for the GridView?
Jun 4 '07 #4
gomzi
304 100+
Have you tried implementing the function that handles the PageIndexChanged 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 Expert Mod 8TB
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 100+
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(depending on the page requested by the user).
Jun 4 '07 #7
Frinavale
9,735 Expert Mod 8TB
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(depending 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 100+
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
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
gomzi
304 100+
Thanks a lot Vijeybabu for addressing the issue in detail.

But won't this method be putting a lot of load on the server, since you are effectively storing the data in the cache?

Also, I was looking for a solution where-in the required data is only retrieved from the database (the trip to the server and back doesn't really matter in comparison to a solution wherein the data is stored in the cache) depending on the page number.

Any idea on how that could be done?

Thanks,
Gomzi.
Jun 5 '07 #11
Frinavale
9,735 Expert Mod 8TB
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.
...
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)
Thank you so much for your detailed response Vijeybabu!
It was very informative.

-Frinny
Jun 5 '07 #12

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

Similar topics

0
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...
0
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...
2
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. ...
2
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
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...
1
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...
0
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...
3
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.