How to do more advanced paging with the DataGrid control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Walzenbach

    How to do more advanced paging with the DataGrid control

    Hi,



    I have a question regarding the DataGrid control. If paging is enabled the
    grid binds the data, sets the paging on the top/bottom (or however it is set
    up) and throws away unnecessary data. So far so good for a tiny amount of
    data but if some 100000 of rows are the source this approach is stupid.



    I therefore want to supply the grid with only the data it needs but then are
    faced with the following problem. How can the grid be set up that the paging
    UI (1.4 5 6.10) is displayed correctly? If the source e.g. is 1000 rows and
    paging 20 rows the user would expect the paging UI to display 1 - 50. Since
    the grid only is bound to 20 rows now paging UI will be available.



    Does anybody know how to overcome this limitation? I thought about creating
    my own version of the DataGrid control but don't know how to start? How can
    I figure out how the DataGrid works to get an idea of what is to change?



    Thank you a lot in advance!



    Daniel


  • Peter Styk

    #2
    Re: How to do more advanced paging with the DataGrid control

    I use this code

    private PagedDataSource DoPaging(Conten ts contents)

    {

    pagedData.DataS ource = contents;

    pagedData.Allow Paging = true;


    try

    {

    pagedData.Curre ntPageIndex =
    Int32.Parse(Req uest.QueryStrin g[pageNoParam].ToString());

    }

    catch

    {

    pagedData.Curre ntPageIndex = 0;

    }

    btnPrev.Visible = !pagedData.IsFi rstPage;

    btnNext.Visible = !pagedData.IsLa stPage;

    pages.Text = @"<p align=""center" "><b>&nbsp; </b>PAGE:";

    for (int x = 1; x <= pagedData.PageC ount; x++)

    {

    // if current page then

    if (pagedData.Curr entPageIndex + 1 == x)

    {

    pages.Text += " | ";

    pages.Text += "<b>" + (pagedData.Curr entPageIndex + 1).ToString() + "</b>";

    }

    else

    {

    pages.Text += " | ";

    string oldQueryString = Util.GetQuerySt ringText(Reques t.QueryString,
    pageNoParam);

    pages.Text += "<a href=" + oldQueryString + "&" + pageNoParam + "=" + (x -
    1).ToString() + ">";

    pages.Text += x + "</a>";

    }

    }

    pages.Text += @" | </p>";


    return pagedData;

    }

    sorry no indents, it shortens your dataset, that;s what PagedDataSource
    does. You will need two buttons for left and right and each will need pass
    parameters (pageNumber) to next page so the object can figure out the offset



    private void btnPrev_Click(o bject sender, System.Web.UI.I mageClickEventA rgs
    e)

    {

    string oldQueryString = Util.GetQuerySt ringText(Reques t.QueryString,
    pageNoParam);

    Response.Redire ct(oldQueryStri ng + "&" + pageNoParam + "=" +
    (pagedData.Curr entPageIndex - 1));

    }

    private void btnNext_Click(o bject sender, System.Web.UI.I mageClickEventA rgs
    e)

    {

    string oldQueryString = Util.GetQuerySt ringText(Reques t.QueryString,
    pageNoParam);

    Response.Redire ct(oldQueryStri ng + "&" + pageNoParam + "=" +
    (pagedData.Curr entPageIndex + 1));

    }





    now all you need is to drop your current dataset and execute it



    pagedData.PageS ize = gridSize;

    dlList.RepeatCo lumns = gridColumns;

    dlList.DataSour ce = DoPaging(conten ts);

    dlList.DataBind ();







    define you paged data at the top of your class




    protected PagedDataSource pagedData = new PagedDataSource ();







    her ya go



    Peter











    "Daniel Walzenbach" <daniel.walzenb ach.NOSPAM@freu denberg.de> wrote in
    message news:u6Rnt3D#EH A.3236@TK2MSFTN GP15.phx.gbl...[color=blue]
    > Hi,
    >
    >
    >
    > I have a question regarding the DataGrid control. If paging is enabled the
    > grid binds the data, sets the paging on the top/bottom (or however it is[/color]
    set[color=blue]
    > up) and throws away unnecessary data. So far so good for a tiny amount of
    > data but if some 100000 of rows are the source this approach is stupid.
    >
    >
    >
    > I therefore want to supply the grid with only the data it needs but then[/color]
    are[color=blue]
    > faced with the following problem. How can the grid be set up that the[/color]
    paging[color=blue]
    > UI (1.4 5 6.10) is displayed correctly? If the source e.g. is 1000 rows[/color]
    and[color=blue]
    > paging 20 rows the user would expect the paging UI to display 1 - 50.[/color]
    Since[color=blue]
    > the grid only is bound to 20 rows now paging UI will be available.
    >
    >
    >
    > Does anybody know how to overcome this limitation? I thought about[/color]
    creating[color=blue]
    > my own version of the DataGrid control but don't know how to start? How[/color]
    can[color=blue]
    > I figure out how the DataGrid works to get an idea of what is to change?
    >
    >
    >
    > Thank you a lot in advance!
    >
    >
    >
    > Daniel
    >
    >[/color]


    Comment

    • Daniel Walzenbach

      #3
      Re: How to do more advanced paging with the DataGrid control

      Peter,

      thanks for the tip.

      Daniel

      "Peter Styk" <ilman@dobrebop olskie.NoNoNo.c om> schrieb im Newsbeitrag
      news:%23FdOZvE% 23EHA.2196@TK2M SFTNGP11.phx.gb l...[color=blue]
      >I use this code
      >
      > private PagedDataSource DoPaging(Conten ts contents)
      >
      > {
      >
      > pagedData.DataS ource = contents;
      >
      > pagedData.Allow Paging = true;
      >
      >
      > try
      >
      > {
      >
      > pagedData.Curre ntPageIndex =
      > Int32.Parse(Req uest.QueryStrin g[pageNoParam].ToString());
      >
      > }
      >
      > catch
      >
      > {
      >
      > pagedData.Curre ntPageIndex = 0;
      >
      > }
      >
      > btnPrev.Visible = !pagedData.IsFi rstPage;
      >
      > btnNext.Visible = !pagedData.IsLa stPage;
      >
      > pages.Text = @"<p align=""center" "><b>&nbsp; </b>PAGE:";
      >
      > for (int x = 1; x <= pagedData.PageC ount; x++)
      >
      > {
      >
      > // if current page then
      >
      > if (pagedData.Curr entPageIndex + 1 == x)
      >
      > {
      >
      > pages.Text += " | ";
      >
      > pages.Text += "<b>" + (pagedData.Curr entPageIndex + 1).ToString() +
      > "</b>";
      >
      > }
      >
      > else
      >
      > {
      >
      > pages.Text += " | ";
      >
      > string oldQueryString = Util.GetQuerySt ringText(Reques t.QueryString,
      > pageNoParam);
      >
      > pages.Text += "<a href=" + oldQueryString + "&" + pageNoParam + "=" + (x -
      > 1).ToString() + ">";
      >
      > pages.Text += x + "</a>";
      >
      > }
      >
      > }
      >
      > pages.Text += @" | </p>";
      >
      >
      > return pagedData;
      >
      > }
      >
      > sorry no indents, it shortens your dataset, that;s what PagedDataSource
      > does. You will need two buttons for left and right and each will need
      > pass
      > parameters (pageNumber) to next page so the object can figure out the
      > offset
      >
      >
      >
      > private void btnPrev_Click(o bject sender,
      > System.Web.UI.I mageClickEventA rgs
      > e)
      >
      > {
      >
      > string oldQueryString = Util.GetQuerySt ringText(Reques t.QueryString,
      > pageNoParam);
      >
      > Response.Redire ct(oldQueryStri ng + "&" + pageNoParam + "=" +
      > (pagedData.Curr entPageIndex - 1));
      >
      > }
      >
      > private void btnNext_Click(o bject sender,
      > System.Web.UI.I mageClickEventA rgs
      > e)
      >
      > {
      >
      > string oldQueryString = Util.GetQuerySt ringText(Reques t.QueryString,
      > pageNoParam);
      >
      > Response.Redire ct(oldQueryStri ng + "&" + pageNoParam + "=" +
      > (pagedData.Curr entPageIndex + 1));
      >
      > }
      >
      >
      >
      >
      >
      > now all you need is to drop your current dataset and execute it
      >
      >
      >
      > pagedData.PageS ize = gridSize;
      >
      > dlList.RepeatCo lumns = gridColumns;
      >
      > dlList.DataSour ce = DoPaging(conten ts);
      >
      > dlList.DataBind ();
      >
      >
      >
      >
      >
      >
      >
      > define you paged data at the top of your class
      >
      >
      >
      >
      > protected PagedDataSource pagedData = new PagedDataSource ();
      >
      >
      >
      >
      >
      >
      >
      > her ya go
      >
      >
      >
      > Peter
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      > "Daniel Walzenbach" <daniel.walzenb ach.NOSPAM@freu denberg.de> wrote in
      > message news:u6Rnt3D#EH A.3236@TK2MSFTN GP15.phx.gbl...[color=green]
      >> Hi,
      >>
      >>
      >>
      >> I have a question regarding the DataGrid control. If paging is enabled
      >> the
      >> grid binds the data, sets the paging on the top/bottom (or however it is[/color]
      > set[color=green]
      >> up) and throws away unnecessary data. So far so good for a tiny amount of
      >> data but if some 100000 of rows are the source this approach is stupid.
      >>
      >>
      >>
      >> I therefore want to supply the grid with only the data it needs but then[/color]
      > are[color=green]
      >> faced with the following problem. How can the grid be set up that the[/color]
      > paging[color=green]
      >> UI (1.4 5 6.10) is displayed correctly? If the source e.g. is 1000 rows[/color]
      > and[color=green]
      >> paging 20 rows the user would expect the paging UI to display 1 - 50.[/color]
      > Since[color=green]
      >> the grid only is bound to 20 rows now paging UI will be available.
      >>
      >>
      >>
      >> Does anybody know how to overcome this limitation? I thought about[/color]
      > creating[color=green]
      >> my own version of the DataGrid control but don't know how to start? How[/color]
      > can[color=green]
      >> I figure out how the DataGrid works to get an idea of what is to change?
      >>
      >>
      >>
      >> Thank you a lot in advance!
      >>
      >>
      >>
      >> Daniel
      >>
      >>[/color]
      >
      >[/color]


      Comment

      Working...