CodeSmith Community
Your Code. Your Way. Faster!

null ref execption in EntityGridView.OnPreRender

Latest post 08-02-2007 7:20 AM by SideShowJon. 2 replies.
  • 07-30-2007 8:58 PM

    • SideShowJon
    • Not Ranked
    • Joined on 07-31-2007
    • Hertfordshire, UK
    • Posts 6
    • Points 200

    null ref execption in EntityGridView.OnPreRender

    Bug: null ref execption in
    Class: EntityGridView.cs 
    Proc:

    protected override void OnPreRender(EventArgs e)
    {
       base.OnPreRender(e);
       if (this.RecordsCount > 0 && this.AllowPaging)
      {
        _gridPagerRow.Visible = true; // execption thrown here
      }
    }

    Detail:
    _gridPagerRow was null and this.AllowPaging was evaluating to true, although set to false on page the default skin overrode the page settings.  I set PagerSettings-Visible="false" because AllowPaging="false" did not stop the paging control displaying.
    // Page:
    <data:EntityGridView
         AllowPaging="false"
         PagerSettings-Visible="false"
         ... />
    // Default.skin:
    <data:EntityGridView runat="server"
         AllowPaging="true"
         AllowSorting="true"
         PageSize="10"
         ... />

    Fix:
    Change EntityGridView.OnPreRender if clause to:

     if (!(
         !this.AllowPaging
         || !(this.PagerSettings != null && this.PagerSettings.Visible)
         || this.RecordsCount > this.PageSize
        ))


    AND disable theme on page or modify the skin

    Filed under: ,
    • Post Points: 60
  • 07-31-2007 8:17 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,880

    Re: null ref execption in EntityGridView.OnPreRender

    SideShowJon,

    Thanks for the report. Fix applied (partially) in rev. 607

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 08-02-2007 7:20 AM In reply to

    • SideShowJon
    • Not Ranked
    • Joined on 07-31-2007
    • Hertfordshire, UK
    • Posts 6
    • Points 200

    Re: null ref execption in EntityGridView.OnPreRender

    Thanks mike

    I also notice that DisplayPageSizeSelector only checks Allow paging.
    Suggest adding a condition test for paging like

            private bool TestPagingRowRequired()
            {
              return (this.AllowPaging
                       && (this.PagerSettings != null && this.PagerSettings.Visible)
                       && this.RecordsCount > this.PageSize
                       );
            }
    

    and calling in
            private void DisplayPageSizeSelector(GridViewRow dgItem)
            {
              if (!TestPagingRowRequired()) return;
              ...
    and
            protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
    
                if (TestPagingRowRequired())
                {
                    _gridPagerRow.Visible = true;
                }
            }
    I also noticed that when the pager row is displayed that OnRowCreated gets called twice for the pager row.
    • Post Points: 5
Page 1 of 1 (3 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems