473,396 Members | 1,775 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,396 software developers and data experts.

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
Nov 19 '05 #1
2 1726
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RelaxoRy | last post by:
sqlConnection1.Open(); myReader = sqlCommand1.ExecuteReader(); DataGrid1.DataSource = myReader; DataGrid1.DataBind(); myReader.Close(); sqlConnection1.Close(); The Datagrid populates fine. ...
1
by: Yangtsi River | last post by:
Hi, I am adding a paging function to a datagrid control, the datasource is a DataSet Object. Based on some articles, I just add some attributes to datagrid, ie....
2
by: Steven K | last post by:
Hello, I am converting an ASP page to ASP.Net. In one page, I am using record paging. I have read that while the DataGrid control has paging, it can tax resources. So I did a Google and found...
1
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
2
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
1
by: MattC | last post by:
Hi, I am trying to export the contents of a DataGrid to Excel. I have already found the following articles: http://support.microsoft.com/default.aspx?scid=kb;en-us;317719...
2
by: Axel Dahmen | last post by:
Hi, I'm using a DataGrid control to show a table's content with paging. For navigation through the pages I'm using the DataGrid's intrinsic navigation section. My problem: The DataGrid...
5
by: Donald Adams | last post by:
Hi, I will have both web and win clients and would like to page my data. I could not find out how the datagrid control does it's paging though I did find some sample code that says they do it...
6
by: cmrchs | last post by:
Hello, I have set the Allowpaging property to true in a standard DataGrid- control (System.Web.UI.WebControls). when run in the browser i get the first records in the first page, there are 5...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.