Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2011, 06:03 PM
Registered User
 
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 15 Page 535 footer issue

This is so minute I sort of feel silly asking but for some reason the page numbers in the footer of my grid appears just fine on the first page but when I go to the second page the page numbers in the footer take on the same grey background that the alternating columns have. The row is blue, it is just the page numbers that have the grey background.

Here is the code copied from my editor:

Code:
    <asp:GridView runat="server" CssClass="GridView">
      <HeaderStyle CssClass="GridViewHeaderStyle" />
      <PagerStyle CssClass="GridViewPagerStyle" />
      <SortedAscendingHeaderStyle CssClass="GridViewSortedAscendingHeaderStyle" />
      <SortedDescendingHeaderStyle CssClass="GridViewSortedDescendingHeaderStyle" />
    </asp:GridView>

<script type="text/javascript">
    $(function ()
    {
      $('.GridView tr:odd:not(.GridViewPagerStyle)').addClass('GridViewAlternatingRowStyle');
    });
  </script>
What's really strange is that I have an odd number of records, and so that means my last record has a grey background, I would assume that an error would show a white background as the grey only appears on alternating lines.
 
Old February 10th, 2011, 06:29 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I think this is actually a flaw in the book. To see why this happens, take a look at the HTML for the pager bar:

Code:
<table class="GridView" cellspacing="0" cellpadding="4" ...>
<tr> ..... Normal rows here </tr>
<tr class="GridViewPagerStyle">
  <td colspan="3">
    <table>
    <tr>
      <td><span>1</span></td><td>.... Page numbers here </td>
    </tr>
  </table>
  </td>
</tr>
</table>
As you can see, the Pager Bar is a table row of its own. So when this jQuery code fires:

Code:
$('.GridView tr:odd:not(.GridViewPagerStyle)').addClass('GridViewAlternatingRowStyle');
It finds *all* <tr> elements within the GridView table and correctly ignores the row with the class GridViewPagerStyle. However, the pager bar itself contains another <tr> which *is* matched with this jQuery code,

So, I guess the correct way to fix this is to use CSS's direct descendants, which you define using a > between elements. That is:

.GridView > tr

would find all <tr> elements that are direct children of the .GridView table. Except that it doesn't. If you don't specify a <tbody> element explicitly, browsers create one for you. So, the correct way to find the direct <tr> elements would be:

.GridView > tbody > tr

which brings the entire statement to this:

Code:
$('.GridView > tbody > tr:odd:not(.GridViewPagerStyle)').addClass('GridViewAlternatingRowStyle');
In case you have a browser that doesn't create a tbody implicitly, this should work as well:

.GridView > * > tr

Long story for a simple problem ;-) I guess I just never looked at page 2 with an odd page size.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Try It Out Page 535 jlransford BOOK: Beginning ASP.NET 4 : in C# and VB 2 September 9th, 2010 09:17 AM
CHAPTER 15,PAGE 533 dyla BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 April 14th, 2010 01:20 PM
CHAPTER 15,PAGE 533 dyla BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 0 April 13th, 2010 10:58 AM
Chap 15 pg 535: SMTP error (requires secure connection, authentication and ssl) tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 8 July 19th, 2009 04:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.