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

Problem with paging buttons > 10

2 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Morten
Top achievements
Rank 1
Morten asked on 30 Aug 2011, 04:06 PM
Hi,

I'm having a problem with the paging buttons. The initial buttons 1-10 works just fine, but when I go to "..." (landing at 11), all the buttons will update their text, but will still be bound to the same events as their previous button IDs had, meaning that if I press 17, I end up back on back 8.

I've searched your forums for similar issues and found http://www.telerik.com/community/forums/aspnet-ajax/grid/355586-radgrid-paging-problem.aspx however this did not help me on the way to a solution.

In order to do some error searching, I've dumbed down an example as much as possible, leaving me with :

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SimpleView.ascx.cs" Inherits="AccessToWeb.Web.SimpleView" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<telerik:RadScriptManager ID="RadScriptManager" runat="server"></telerik:RadScriptManager>
<!-- content start -->
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<div style="padding-left:20px;">
    <telerik:RadGrid ID="RadGrid1" AllowPaging="True" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" GridLines="None" EnableViewState="true">
      <MasterTableView EnableViewState="true" />
      <PagerStyle Mode="NumericPages" />
    </telerik:RadGrid>
</div>

And codebehind:

namespace AccessToWeb.Web
{
    public partial class SimpleView : System.Web.UI.UserControl
    {
        private string _con, _query;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            _con = Sitecore.Context.Item["Connectionstring"];
            _query = Sitecore.Context.Item["Select statement"];
 
            if (string.IsNullOrEmpty(_con) || string.IsNullOrEmpty(_query))
            {
                this.Visible = false;
                return;
            }
        }
 
        public DataTable GetDataTable(string query)
        {
            SqlConnection conn = new SqlConnection(_con);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand(query, conn);
 
            DataTable myDataTable = new DataTable();
 
            conn.Open();
            try
            {
                adapter.Fill(myDataTable);
            }
            finally
            {
                conn.Close();
            }
 
            return myDataTable;
        }
 
        protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = GetDataTable(_query);
        }
    }
}


If I instead of NumericPages use NextPrevAndNumeric, the same problem exists, but the Next button will always point at page 2, no matter which page I am on.

2 Answers, 1 is accepted

Sort by
0
Morten
Top achievements
Rank 1
answered on 31 Aug 2011, 11:34 AM
It works fine if I set  EnableViewState="false" on the grid and masterview - but it was my understanding that this was not the preferred settings? 
0
Marin
Telerik team
answered on 02 Sep 2011, 07:51 AM
Hello Morten,

 I checked your code and the paging was working fine on my side. The only difference is that I bound the grid to a Northwind database for testing purposes. You can check your entity model and whether it returns the correct data. You can also have a look at the attached page where the grid is bound to a collection of numbers. So most likely the problem is in the underlying data model rather than in grid configuration.

Kind regards,
Marin
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
Morten
Top achievements
Rank 1
Answers by
Morten
Top achievements
Rank 1
Marin
Telerik team
Share this question
or