How to implement custom paging in asp.net?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gomzi
    Contributor
    • Mar 2007
    • 304

    How to implement custom paging in asp.net?

    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.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by gomzi
    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

    Comment

    • gomzi
      Contributor
      • Mar 2007
      • 304

      #3
      Originally posted by Frinavale
      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.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by gomzi
        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?

        Comment

        • gomzi
          Contributor
          • Mar 2007
          • 304

          #5
          Originally posted by Frinavale
          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.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by gomzi
            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

            Comment

            • gomzi
              Contributor
              • Mar 2007
              • 304

              #7
              Originally posted by Frinavale
              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).

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Originally posted by gomzi
                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

                Comment

                • gomzi
                  Contributor
                  • Mar 2007
                  • 304

                  #9
                  Originally posted by Frinavale
                  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.

                  Comment

                  • Vijeybabu
                    New Member
                    • Jun 2007
                    • 2

                    #10
                    Originally posted by gomzi
                    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.
                    [code=cpp]
                    int TotalNoRows; (Globle Variable)
                    int NextPage; (Globle Variable)
                    DataView dvue; (Globle Variable)

                    protected void Page_Load(objec t sender, EventArgs e)
                    {
                    if (!IsPostBack)
                    {
                    Cache["PageCount"] = 1;
                    int Loadpage = (int)Cache["PageCount"];
                    BindGrid(Loadpa ge);
                    btnPrev.Enabled = false;
                    }
                    int PgNo = Convert.ToInt32 (Request.QueryS tring["pageno"]);
                    if (PgNo > 1)
                    {
                    if (!IsPostBack)
                    {
                    btnPrev.Enabled = true;
                    BindGrid(PgNo);
                    }
                    }
                    }

                    protected void btnNext_Click(o bject sender, EventArgs e)
                    {
                    btnPrev.Enabled = true;
                    //-----------------
                    NextPage = 1 + (int)Cache["PageCount"];
                    BindGrid(NextPa ge);
                    }

                    protected void btnPrev_Click(o bject sender, EventArgs e)
                    {
                    btnNext.Enabled = true;
                    btnNext.Text = "Next";

                    //--------------

                    NextPage = (int)Cache["PageCount"] - 1;
                    BindGrid(NextPa ge);
                    if (NextPage == 1)
                    btnPrev.Enabled = false;
                    }

                    private void BindGrid(int PageNo)
                    {
                    dvue = (DataView)Cache["MemberData "];
                    if (dvue == null)
                    {
                    string strSQL = "SELECT EmployeeID,Firs tName,LastName FROM Employees";
                    SqlDataAdapter da = new SqlDataAdapter( strSQL, net.webindia.Co nn_Open());

                    DataSet ds = new DataSet();
                    DataTable tbl = ds.Tables.Add(" BasicInformatio n");

                    DataColumn col = tbl.Columns.Add ("RowID", typeof(int));
                    col.AutoIncreme nt = true;
                    col.AutoIncreme ntSeed = 1;
                    col.AutoIncreme ntStep = 1;

                    da.Fill(ds, "BasicInformati on");
                    dvue = new DataView(tbl);

                    Cache["MemberData "] = dvue;
                    Response.Write( "Data Loaded from the Database at: " + DateTime.Now.To ShortTimeString ());

                    TotalNoRows = ds.Tables[0].Rows.Count;
                    Cache["TotalNoRow s"] = TotalNoRows;
                    }
                    //Response.Write( "Total Records: "+ Cache["TotalNoRow s"].ToString());

                    int intPageSize = 10;
                    int intPageNum = PageNo;
                    Cache["PageCount"] = PageNo;
                    //For all the Popup page back link we are passing the pageno.


                    if (((intPageNum - 1) * intPageSize) <= (int)Cache["TotalNoRow s"])
                    dvue.RowFilter = "RowID > " + (intPageNum - 1) * intPageSize + " and RowID <= " + intPageNum *

                    intPageSize;
                    else
                    {
                    //To find the Last Record and to disable the Next button.
                    btnNext.Enabled = false;
                    btnNext.Text = "End";
                    }

                    //DataGrid binding using DataView.
                    dg1.DataSource = dvue;
                    dg1.DataBind();

                    //To find the Last Record and to disable the Next button.
                    if (dg1.Items.Coun t < 10)
                    {
                    btnNext.Enabled = false;
                    btnNext.Text = "End";
                    }
                    }
                    [/code]
                    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)

                    Comment

                    • gomzi
                      Contributor
                      • Mar 2007
                      • 304

                      #11
                      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.

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        Originally posted by Vijeybabu
                        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

                        Comment

                        Working...