By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,081 Members | 861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,081 IT Pros & Developers. It's quick & easy.

How to do more advanced paging with the DataGrid control

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I use this code

private PagedDataSource DoPaging(Contents contents)

{

pagedData.DataSource = contents;

pagedData.AllowPaging = true;
try

{

pagedData.CurrentPageIndex =
Int32.Parse(Request.QueryString[pageNoParam].ToString());

}

catch

{

pagedData.CurrentPageIndex = 0;

}

btnPrev.Visible = !pagedData.IsFirstPage;

btnNext.Visible = !pagedData.IsLastPage;

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

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

{

// if current page then

if (pagedData.CurrentPageIndex + 1 == x)

{

pages.Text += " | ";

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

}

else

{

pages.Text += " | ";

string oldQueryString = Util.GetQueryStringText(Request.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(object sender, System.Web.UI.ImageClickEventArgs
e)

{

string oldQueryString = Util.GetQueryStringText(Request.QueryString,
pageNoParam);

Response.Redirect(oldQueryString + "&" + pageNoParam + "=" +
(pagedData.CurrentPageIndex - 1));

}

private void btnNext_Click(object sender, System.Web.UI.ImageClickEventArgs
e)

{

string oldQueryString = Util.GetQueryStringText(Request.QueryString,
pageNoParam);

Response.Redirect(oldQueryString + "&" + pageNoParam + "=" +
(pagedData.CurrentPageIndex + 1));

}

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

pagedData.PageSize = gridSize;

dlList.RepeatColumns = gridColumns;

dlList.DataSource = DoPaging(contents);

dlList.DataBind();



define you paged data at the top of your class


protected PagedDataSource pagedData = new PagedDataSource();



her ya go

Peter



"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in
message news:u6**************@TK2MSFTNGP15.phx.gbl...
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

Nov 19 '05 #2

P: n/a
Peter,

thanks for the tip.

Daniel

"Peter Styk" <il***@dobrebopolskie.NoNoNo.com> schrieb im Newsbeitrag
news:%2******************@TK2MSFTNGP11.phx.gbl...
I use this code

private PagedDataSource DoPaging(Contents contents)

{

pagedData.DataSource = contents;

pagedData.AllowPaging = true;
try

{

pagedData.CurrentPageIndex =
Int32.Parse(Request.QueryString[pageNoParam].ToString());

}

catch

{

pagedData.CurrentPageIndex = 0;

}

btnPrev.Visible = !pagedData.IsFirstPage;

btnNext.Visible = !pagedData.IsLastPage;

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

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

{

// if current page then

if (pagedData.CurrentPageIndex + 1 == x)

{

pages.Text += " | ";

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

}

else

{

pages.Text += " | ";

string oldQueryString = Util.GetQueryStringText(Request.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(object sender,
System.Web.UI.ImageClickEventArgs
e)

{

string oldQueryString = Util.GetQueryStringText(Request.QueryString,
pageNoParam);

Response.Redirect(oldQueryString + "&" + pageNoParam + "=" +
(pagedData.CurrentPageIndex - 1));

}

private void btnNext_Click(object sender,
System.Web.UI.ImageClickEventArgs
e)

{

string oldQueryString = Util.GetQueryStringText(Request.QueryString,
pageNoParam);

Response.Redirect(oldQueryString + "&" + pageNoParam + "=" +
(pagedData.CurrentPageIndex + 1));

}

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

pagedData.PageSize = gridSize;

dlList.RepeatColumns = gridColumns;

dlList.DataSource = DoPaging(contents);

dlList.DataBind();



define you paged data at the top of your class


protected PagedDataSource pagedData = new PagedDataSource();



her ya go

Peter



"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in
message news:u6**************@TK2MSFTNGP15.phx.gbl...
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


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.