Wednesday, May 28, 2014

The VisibleRowCount property of a DevExpress ASPxGridView will reveal how many total rows are in the control.

Following this, I finished a means for adjusting the height of a div holding yet another div which had absolute positioning holding an ASPxGridView named Foo when Foo's height changed due to pagination changing. My C# looks like this:

namespace MyProject.MyFolder
{
   public partial class MyWebFormCodeBehind
   {
      private int _rowHeight;
      private int _headerAndFooterHeight;
      private int _pageSize;
      
      public MyWebFormCodeBehind()
      {
         _rowHeight = 26;
         _headerAndFooterHeight = 70;
         _pageSize = 10;
      }
      
      private void Foo_PageIndexChanged(object sender, EventArgs e)
      {
         int pageIndex = (sender as ASPxGridView).PageIndex;
         int totalRows = (sender as ASPxGridView).VisibleRowCount;
         if (pageIndex > -1)
         {
            decimal division = totalRows /_pageSize;
            int remainder = totalRows % _pageSize;
            int lastPage = Convert.ToInt32(Math.Floor(division));
            if (pageIndex == lastPage && remainder != 0)
            {
               Foo.JSProperties["cp_ToAdjustHeightTo"] = (remainder * _rowHeight) +
                     _headerAndFooterHeight;
            } else {
               Foo.JSProperties["cp_ToAdjustHeightTo"] = (_pageSize * _rowHeight) +
                     _headerAndFooterHeight;
            }
         } else {
            Foo.JSProperties["cp_ToAdjustHeightTo"] = (totalRows * _rowHeight) +
                  _headerAndFooterHeight;
         }
      }

 
 

...and in JavaScript I have:

function AdjustHeightOfDivHoldingPaymentConfigurations(s, e) {
   var middlemanDiv = document.getElementById("MiddlemanDiv");
   middlemanDiv.style.height = s.cp_ToAdjustHeightTo + "px";
}

 
 

What are the three calculations in C#? From the bottom up there are...

  1. This circumstance is for pressing the "All" button and showing every record at once.
    Foo.JSProperties["cp_ToAdjustHeightTo"] = (totalRows * _rowHeight) +
          _headerAndFooterHeight;

     
  2. This is for showing almost any page in the pagination. There is one exception however.
    Foo.JSProperties["cp_ToAdjustHeightTo"] = (_pageSize * _rowHeight) +
          _headerAndFooterHeight;

     
  3. Here is the exception. If the last page in the pagination is not a complete page (with ten line items) then we use this.
    Foo.JSProperties["cp_ToAdjustHeightTo"] = (remainder * _rowHeight) +
          _headerAndFooterHeight;

If the number of records is equal to or less than the number of records in one page (ten) then the pagination controls will be disabled and all of this will be moot.

No comments:

Post a Comment