Page 1 of 1

cb:AbleGridView page size changing event

Posted: Fri May 23, 2014 4:08 am
by jmestep
I am using this gridview with a datasource from a database query in the code behind and am trying to get the page size on the grid to change. I change it, then it changes right back. I was having trouble with the paging itself but figured that out by using the following

Code: Select all

protected void ShipmentsGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.ShipmentsGrid.PageIndex = e.NewPageIndex;
            BindShipmentsGrid();        

        }
How can I pick up the page size changed event? I tried Request.Form and was able to get the new size, but was having trouble inserting it at the right sequence in the page events. I'm sure there is a better way, but I just haven't found it yet. It seems that all the times you use the control is from an object datasource.
Thanks

Re: cb:AbleGridView page size changing event

Posted: Thu Jun 26, 2014 3:50 am
by mazhar
Did you provided the PageSize value on gridview itself in markup? If yes what was it?

Re: cb:AbleGridView page size changing event

Posted: Thu Jun 26, 2014 4:43 am
by jmestep
I really had to dig on this one to remember what I was working on more than a month ago!
Here is the code- I had to set it at 50 since it wouldn't page.

Code: Select all

<cb:AbleGridView  ID="ShipmentsGrid" SkinID="PagedList" runat="server" AllowPaging="True"  AutoGenerateColumns="False"  OnPageIndexChanging="ShipmentsGrid_PageIndexChanging" PageSize="50" OnRowDataBound="ShipmentsGrid_RowDataBound" ShowHeader="true" GridLines="None" PagerSettings-Position="TopAndBottom" >
Here are things I tried in the code behind, as far as I remember

Code: Select all

in page load
               ShipmentsGrid.PageSizeOptions= "50:50";
                ShipmentsGrid.PagerMode = CommerceBuilder.UI.WebControls.AbleGridView.PagerType.Custom;
                //if (Page.IsPostBack)
                //{
                //    ShipmentsGrid.PageSizeOptions = string.Format("{0}:{0}|{1}:{1}", 20, 40);
                //}
                 BindShipmentsGrid();

Code: Select all

 protected void Page_Init(object sender, EventArgs e)
        {
            //doesn't work
            if (Page.IsPostBack)
            {
                //int pageSize = AlwaysConvert.ToInt(Request.Form["ctl00$MainContent$ShipmentsGrid$ctl01$ctl11"]);
                //ShipmentsGrid.PageSize = pageSize;
                //ShipmentsGrid.PageSizeOptions = string.Format("{0}:{0}|{1}:{1}",20,40);
            }
        }
Thanks

Re: cb:AbleGridView page size changing event

Posted: Thu Jun 26, 2014 11:35 pm
by mazhar
Here are the defaults for PageSizeOptions

Code: Select all

PageSizeOptions = "Show All:0|5:5|10:10|20:20|50:50|100:100"
Instead of setting them via code better try to set it in HTML markup. Like you set other properties on GridView. I was thinking maybe page size you provided was not in available size options.

Re: cb:AbleGridView page size changing event

Posted: Fri Jun 27, 2014 4:05 am
by jmestep
I knew those were the defaults from looking at the source code. I have removed all the page size settings from the code behind and put this in the markup and it still happens. I'll dig around further.

Code: Select all

<cb:AbleGridView  ID="ShipmentsGrid" SkinID="PagedList" runat="server" AllowPaging="True"  AutoGenerateColumns="False"  OnPageIndexChanging="ShipmentsGrid_PageIndexChanging" PageSize="20" OnRowDataBound="ShipmentsGrid_RowDataBound" ShowHeader="true" GridLines="None" PagerSettings-Position="TopAndBottom" PageSizeOptions = "Show All:0|5:5|10:10|20:20|50:50|100:100" >

Re: cb:AbleGridView page size changing event

Posted: Wed Jul 15, 2015 8:18 am
by jmestep
Well, here I am a year later and am still having the same problem on a different page. The paging works until I select another page size in the dropdown. Is there a method on the grid view that I should trigger when I change the page size? It seems like all of your code using the grid is bound via an object datasource. I am binding from the code behind.
Here is my code and thanks for any help.

Code: Select all

 <cb:AbleGridView ID="KeycodeGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="KeycodeId" AllowPaging="true" PageSize="5"     <cb:AbleGridView ID="KeycodeGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="KeycodeId" AllowPaging="true"  PagerSettings-Position="TopAndBottom"   OnPageIndexChanging="KeycodeGrid_PageIndexChanging"
                    TotalMatchedFormatString="<span id='searchCount'>{0}</span> matching keycodes" 
                    AllowSorting="true" SkinID="PagedList" Width="100%" OnRowCommand="KeycodeGrid_RowCommand" Visible="false"  PageSizeOptions = "Show All:0|5:5|10:10|20:20|50:50|100:100" OnSelectedIndexChanging="KeycodeGrid_SelectedIndexChanging">

Re: cb:AbleGridView page size changing event

Posted: Fri Jul 17, 2015 3:24 am
by AbleMods
I've had similar issues because I didn't notice that viewstate was disabled on the page or on the control in question. Sometimes it's the parent placeholder or parent panel that has viewstate disabled. So even though the page size was getting set in the postback, it wasn't sticking.

To check it, I would set the value and put a breakpoint at the beginning of page_load so I could check the control's PageSize property. Then try to walk forward through the code to see if I can find where it's changing back to a previous value.

Hope that helps. Won't fix it, but could give you a little more insight.

Re: cb:AbleGridView page size changing event

Posted: Fri Jul 17, 2015 12:55 pm
by mazhar
I just tried a small test. On Admin/Marketting/Coupons/Default.aspx I updated the AbleGridView defention like below

Code: Select all

<cb:AbleGridView ID="CouponGrid" runat="server" 
                    AutoGenerateColumns="False" 
                    DataKeyNames="Id"
                    DataSourceID="CouponDs" 
                    AllowPaging="True" 
                    PageSize="1" 
                    TotalMatchedFormatString="<span id='searchCount'>{0}</span> matching coupons" 
                    SkinID="PagedList" 
                    ShowWhenEmpty="False" 
                    AllowMultipleSelections="False"
                    AllowSorting="true" 
                    Width="100%" 
                    DefaultSortExpression="Name" 
                    OnRowDataBound="CouponGrid_RowDataBound"
                    OnRowCommand="CouponGrid_RowCommand" PageSizeOptions="Show All:0|1:1|15:15|20:20|70:70">
Notice the PageSize and PageSizeOptions. It does seems to be working for me.

Re: cb:AbleGridView page size changing event

Posted: Mon Jul 20, 2015 1:12 am
by jmestep
I did finally get this working on a gridview that was bound from the code behind. I had to explicitly disable viewstate on it.

Re: cb:AbleGridView page size changing event

Posted: Tue Jul 21, 2015 5:54 am
by mazhar
Good to know that you have it working.