This is a migrated thread and some comments may be shown as answers.

Pager is showing after postback

17 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Oleg Yaroshevych
Top achievements
Rank 1
Oleg Yaroshevych asked on 10 Jul 2008, 09:37 AM
Hello,

I use RadGrid with paging enabled. When there is only one page in the grid (items count < page size), pager is hidden, but after postback it becomes visible.

Please check my code.

Best regards, Oleg.

Windows XP SP2
RadGrid For ASP.NET AJAX 2008.1.619.35
Visual Studio 2008
.NET 3.5


Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <telerik:RadGrid ID="gridAccounts" runat="server" PageSize="20" AllowPaging="True"
        DataSourceID="ObjectDataSource1">
        <MasterTableView AutoGenerateColumns="false">
            <Columns>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Amount" HeaderText="Amount">
                </telerik:GridBoundColumn>
            </Columns>
            <PagerStyle Visible="true" Mode="NextPrevNumericAndAdvanced" />
        </MasterTableView>
    </telerik:RadGrid>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
        EnablePaging="true" SelectCountMethod="SelectCount" StartRowIndexParameterName="offset"
        MaximumRowsParameterName="count" TypeName="Class1">
        <SelectParameters>
            <asp:ControlParameter Name="searchContext" ControlID="ObjectDataSource1" PropertyName="NamingContainer.Page.SearchContext" />
        </SelectParameters>
    </asp:ObjectDataSource>
    </form>
</body>
</html>


Default.aspx.cs

using System;

public partial class _Default : System.Web.UI.Page
{
  public SearchContext SearchContext
  {
    get
    {
      return new SearchContext() { MinAmount = 10 };
    }
  }
}


Class1.cs

using System;
using System.Collections.Generic;

public class Class1
{
  public Transaction[] GetData(SearchContext searchContext, int offset, int count)
  {
    List<Transaction> transactions = new List<Transaction>();

    for (int i = 0; i < 3; ++i)
      transactions.Add(new Transaction() { Name = "T" + i, Amount = i });

    return transactions.ToArray();
  }

  public int SelectCount(SearchContext searchContext)
  {
    return 3;
  }
}

public class Transaction
{
  public string Name { get; set; }
  public int Amount { get; set; }
}

[Serializable]
public class SearchContext
{
  public int MinAmount { get; set; }
}

17 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 11 Jul 2008, 08:38 AM
Hello Oleg,

Try the following code in the PreRender event of RadGrid:

void RadGrid1_PreRender(object sender, EventArgs e) 
    if (RadGrid1.MasterTableView.Items.Count < RadGrid1.PageSize) 
        RadGrid1.PagerStyle.Visible = false


Kind regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Oleg Yaroshevych
Top achievements
Rank 1
answered on 11 Jul 2008, 03:11 PM
Veli,

Unfortunately your code doesn't work. I even checked it with debugger.

It is not a showstopper for me, but I hope you'll fix this bug till next release.

Best regards, Oleg.
0
Shinu
Top achievements
Rank 2
answered on 14 Jul 2008, 07:19 AM
Hi Oleg,

Can you check whether you have set the PrePrender  Event Handler in the aspx?

ASPX:
 <telerik:RadGrid ID="RadGrid1"  AllowPaging="True" PageSize="10" OnPreRender="RadGrid1_PreRender" > 
              


CS:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if (RadGrid1.MasterTableView.Items.Count < RadGrid1.PageSize
            RadGrid1.PagerStyle.Visible = false;  
    } 

Thanks
Shinu.
0
Oleg Yaroshevych
Top achievements
Rank 1
answered on 14 Jul 2008, 10:04 AM
Shinu,

Yes, I added this code and checked with debugger that this handler is called correctly, but nothing happens - pager is shown after postback. I cannot find an option to attach my project here on forum, but you can use code I provided in my first post. Please note that I'm using latest available Telerik version - 2008.01.0619.35 (I checked with debugger that correct Telerik.Web.UI.dll is loaded).

ASPX
<telerik:RadGrid ID="RadGrid1" runat="server" PageSize="20" AllowPaging="True"
DataSourceID="ObjectDataSource1" OnPreRender="RadGrid1_PreRender">
CS
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
  if (RadGrid1.MasterTableView.Items.Count < RadGrid1.PageSize)
    RadGrid1.PagerStyle.Visible = false;
}
Best regards, Oleg.
0
Princy
Top achievements
Rank 2
answered on 14 Jul 2008, 10:14 AM
Hi Oleg,

Can you try rebinding the Grid in the PreRender event and see whether it is working correctly.

CS:
protected void RadGrid1_PreRender(object sender, EventArgs e)  
{  
  if (RadGrid1.MasterTableView.Items.Count < RadGrid1.PageSize)  
    RadGrid1.PagerStyle.Visible = false;  
    RadGrid1.Rebind();  
}  
 


Thanks
Princy.
0
Veli
Telerik team
answered on 14 Jul 2008, 11:52 AM
Hello Oleg,

Please find attached a sample project I have created for your convenience. It demonstrates RadGrid hiding its Pager item if the data items retrieved from the data source fall below the pager size.

Regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Oleg Yaroshevych
Top achievements
Rank 1
answered on 14 Jul 2008, 12:54 PM
Princy,

Thanks, your code works for me. The only change I added was check for IsPostback to avoid selecting data twice. Code in sample attached by telerik selects data twice.

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
  if (RadGrid1.MasterTableView.Items.Count < RadGrid1.PageSize)
  {
    RadGrid1.PagerStyle.Visible = false;

    if (IsPostBack)
      RadGrid1.Rebind();
  }
}
Now I have to update 20 grids in my application 0_0. Hope, you'll fix this behavior for the rest of your clients.

Thanks, Oleg.
0
Oleg Yaroshevych
Top achievements
Rank 1
answered on 06 Aug 2008, 04:27 PM
Telerik Team,

Did you recognized this issue as a problem? IOW, should I wait for fix, or I should update all my grids using your workaround?

Best regards, Oleg Yaroshevych.
0
Yavor
Telerik team
answered on 07 Aug 2008, 05:39 AM
Hi Oleg,

This issue is not a problem, but rather a difference in the way the functionality was implemented. You can use the latest code posted, or the one in the application posted earlier. The functionality should work in all cases.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
James
Top achievements
Rank 1
answered on 07 Aug 2008, 06:25 AM
What's your exceptions?
How did you fix it?
0
Oleg Yaroshevych
Top achievements
Rank 1
answered on 07 Aug 2008, 01:03 PM
Yavor,

I mean problem with showing pager after postback, not the issue with selecting data twice. So, I was interested in what the status of the "showing pager after postback" issue, do you plan to fix it in the nearest future, or should I use this workaround (I have a lot of grids, so I do not want to do this :) ).

Thanks, Oleg Yaroshevych.
0
Yavor
Telerik team
answered on 11 Aug 2008, 07:37 AM
Hi Oleg,

The pager should actually be hidden automatically.
If we use the code project attached to this message, and if you comment the following code:

.cs
void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        //if (RadGrid1.MasterTableView.Items.Count < RadGrid1.PageSize)  
        //{  
        //    RadGrid1.PagerStyle.Visible = false;  
        //}  
    } 

and then reduce the pageSize, the pager will be removed.
Let me know if you get the same result, or if I am leaving something out.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Oleg Yaroshevych
Top achievements
Rank 1
answered on 14 Aug 2008, 10:51 AM
Yavor,

Your demo doesn't reproduces the problem. Please try to use ObjectDataSource instead of AccessDataSource. You can use the code which I've posted.

Best regards, Oleg.
0
Yavor
Telerik team
answered on 18 Aug 2008, 01:56 PM
Hi Oleg,

Attached to this message, is a sample project, which utilizes an object datasource.
Take a look at it and let me know if I am leaving something out.

Regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Oleg Yaroshevych
Top achievements
Rank 1
answered on 29 Aug 2008, 02:35 PM
Yavor,

Your project works well, but.. There are a lot of differences between your project and my code I've provided in the first post. First of all, you use DataSet instead of business objects, second, you don't use SelectCountMethod, StartRowIndexParameterName, MaximumRowsParameterName parameters ob ObjectDataSource.

Please try my code, you can simply copy&paste it in you project (Default.aspx, Default.aspx.cs, Class1.cs). I hope, you'll be able to reproduce the problem.

Best regards, Oleg Yaroshevych.
0
Yavor
Telerik team
answered on 02 Sep 2008, 05:22 AM
Hello Oleg,

Using only the code posted initially generates a few compilation errors. That is why I used the other sample.
You can replicate the problem, using as little code as possible, in a small working project, and send it to us in a formal support ticket. I will review it and advise you further.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jason
Top achievements
Rank 1
answered on 11 Nov 2008, 03:36 PM
I am having this same issue with version 2008.3.1016.35

I have been able to use the same workaround, however I feel there should be a better solution.

Thanks,
Jason
Tags
Grid
Asked by
Oleg Yaroshevych
Top achievements
Rank 1
Answers by
Veli
Telerik team
Oleg Yaroshevych
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Yavor
Telerik team
James
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Share this question
or