How do I remove the paging links from a data grid when there's only one page?

A

Alan Silver

Hello,

I have been playing with the data grid, which looks very powerful for
providing paged views of your data, but I don't like the way the footer
bits are displayed when there's only one page. You still get the links,
well text really, but they don't mean anything.

Can these be switched off? If not, can I at least add some text to the
footer? I would like to do this anyway as it's not always immediately
obvious that these are paging links.

TIA
 
P

Pat

Alan,
It is very easy. Throw the following code into the bottom of the
function that sources, binds and displays your datagrid. Convention:
name of the datagrid will be 'grdAlan'.

if(grdAlan.PageCount > 1)
grdAlan.PagerStyle.Visible = true;
else
grdAlan.PagerStyle.Visible = false;
 
A

Alan Silver

Alan,
It is very easy. Throw the following code into the bottom of the
function that sources, binds and displays your datagrid. Convention:
name of the datagrid will be 'grdAlan'.

Thanks for the quick response. I tried this, but on the line...
if(grdAlan.PageCount > 1)

the compiler gave an error...

"CS1014: A get or set accessor expected"

Any idea why? I looked in the SDK, and it looks like it should work as
you typed it.
 
A

Alan Silver

the compiler gave an error...

Ignore that, it was my stupid mistake. I put the code in a method and
forgot to add the () after the name, so the compiler thought it was a
property. Ho hum.

I would still like to know if you can add text to the footer. Just
having numbers there is a bit unfriendly. It would be nice if you could
change it to "Go to page 1 2 3..."

Any ideas? Thanks again.
 
U

ujjc001

I did this the other day, but wanted to adjust it to show the current
page like
"Page 3 of 22" - Select page: 1 2 3 4 5 6... >" or something cleaner,
but you get the idea, with the code below you can do what ever you want
in the pager. I've even displayed the total record count in the pager
right aligned. You can add cells and merge cells and do colspans, what
ever you so choose. You could even add rows under or above your
footer.
Jeff


Private Sub YourDGHere_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
YourDGHere.ItemCreated
If e.Item.ItemType = ListItemType.Pager Then
If sender.PageCount = 1 Then
sender.PagerStyle.Visible = False
Else
Dim pageOf As String
Dim tablecellp As TableCell = CType(e.Item.Controls(0),
TableCell)
If sender.PageCount > 1 Then
pageOf = "Select page: "
Else
YourDGHere.PagerStyle.Visible = False
End If
tablecellp.Controls.AddAt(0, New
LiteralControl(pageOf))
End If
End If
End Sub
 
A

Alan Silver

That's fantastic, thanks a lot. I was actually very surprised at the
lack of control you have over this, especially given the amount of
control you have over everything else in the datagrid.

I'll go and play with this. Thanks again
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top