ASP.NET:: Paging on Demand

J

Jignesh Desai

Info::
Most of you must have worked on paging feature of DataGrid. its works fine as long as you have more no of records to show, but if you have configured 20 records per page and no of records you retrieved is less then 20 then also pager gets rendered at the bottom of the grid showing "1". most of us do not bother about it , but Clients ,,,uff...

Solution:
SQLDataAdapter.Fill(DS,"Emp")

If DS.Tables("Emp").Rows.Count > MyDataGrid1.PageSize then
MyDataGrid1.AllowPaging = True
Else
MyDataGrid1.AllowPaging = False
End if

MyDataGrid1.DataBind()

Any better ways?

ya perhaps this could have been reduced to one line also eg.

MyDataGrid1.AllowPaging = ( DS.Tables("Emp").Rows.Count > MyDataGrid1.PageSize )

Anything better then this?

Regards
Jignesh Desai
www.dotnetjini.com
 
E

Edwin Knoppert

Agreed, but you can also extend this paging template with a checkbox to disable it.
I did a similar thing but outside the grid.

"Jignesh Desai" <[email protected]> schreef in bericht Info::
Most of you must have worked on paging feature of DataGrid. its works fine as long as you have more no of records to show, but if you have configured 20 records per page and no of records you retrieved is less then 20 then also pager gets rendered at the bottom of the grid showing "1". most of us do not bother about it , but Clients ,,,uff...

Solution:
SQLDataAdapter.Fill(DS,"Emp")

If DS.Tables("Emp").Rows.Count > MyDataGrid1.PageSize then
MyDataGrid1.AllowPaging = True
Else
MyDataGrid1.AllowPaging = False
End if

MyDataGrid1.DataBind()

Any better ways?

ya perhaps this could have been reduced to one line also eg.

MyDataGrid1.AllowPaging = ( DS.Tables("Emp").Rows.Count > MyDataGrid1.PageSize )

Anything better then this?

Regards
Jignesh Desai
www.dotnetjini.com
 
S

Steven Cheng[MSFT]

Hi Jignesh,

Another means is use the DataGrid's PreRender event and set the
DataGrid.PagerStyle.Visible according to its current page count. e.g:

protected void dgPage_PreRender(object sender, EventArgs e)
{
if (dgPage.PageCount == 1)
{
dgPage.PagerStyle.Visible = false;
}
}


This can make our code just specific to the DataGrid without put in some
other page wide event.....

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Edwin Knoppert" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: ASP.NET:: Paging on Demand
| Date: Tue, 24 Jan 2006 22:11:50 +0100
| Organization: QinIP
| Lines: 117
| Message-ID: <[email protected]>
| References: <[email protected]>
| NNTP-Posting-Host: h8441197235.dsl.speedlinq.nl
| Mime-Version: 1.0
| Content-Type: multipart/alternative;
| boundary="----=_NextPart_000_0016_01C62133.2D11FC80"
| X-Trace: azure.qinip.net 1138137108 8548 84.41.197.235 (24 Jan 2006
21:11:48 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: Tue, 24 Jan 2006 21:11:48 +0000 (UTC)
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli
ne.de!newsfeed.freenet.de!213.132.189.2.MISMATCH!multikabel.net!feed20.multi
kabel.net!news2.euro.net!azure.qinip.net!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:373273
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Agreed, but you can also extend this paging template with a checkbox to
disable it.
| I did a similar thing but outside the grid.
| "Jignesh Desai" <[email protected]> schreef in bericht
| Info::
| Most of you must have worked on paging feature of DataGrid. its works
fine as long as you have more no of records to show, but if you have
configured 20 records per page and no of records you retrieved is less then
20 then also pager gets rendered at the bottom of the grid showing "1".
most of us do not bother about it , but Clients ,,,uff...
| Solution:
| SQLDataAdapter.Fill(DS,"Emp")
| If DS.Tables("Emp").Rows.Count > MyDataGrid1.PageSize then
| MyDataGrid1.AllowPaging = True
| Else
| MyDataGrid1.AllowPaging = False
| End if
| MyDataGrid1.DataBind()
| Any better ways?
| ya perhaps this could have been reduced to one line also eg.
| MyDataGrid1.AllowPaging = ( DS.Tables("Emp").Rows.Count >
MyDataGrid1.PageSize )
| Anything better then this?
| Regards
| Jignesh Desai
| www.dotnetjini.com
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top