Telerik RadGrid Paging - Duplicate records and sticking buttons
Asked Answered
A

2

8

I've recently started using ASP.Net and Telerik's RadGrid but have ran into a problem:

My RadGrid object is within a UserControl object within a Custom Control object within a Page object (which has a script manager).

I have several UserControls within said Custom Control, each containing the markup for a RadGrid object as below:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AreaListRadGrid.ascx.cs" Inherits="WebControls.AreaListRadGrid" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" %>

<telerik:RadAjaxPanel runat="server" ID="radAjaxPanel" 
            EnableAJAX="true" LoadingPanelID="radAjaxLoadingPanel">
    <telerik:RadGrid AllowPaging="true" AutoGenerateColumns="false" DataSourceID="gridData" EnableViewState="true" GridLines="None" ID="radGrid" runat="server">
        <PagerStyle Mode="NumericPages" />
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="ColA" HeaderText="A" />
                <telerik:GridBoundColumn DataField="ColB" HeaderText="B" />
                <telerik:GridBoundColumn DataField="ColC" HeaderText="C" />
                <telerik:GridBoundColumn DataField="ColD" HeaderText="D" />
                <telerik:GridBoundColumn DataField="ColE" HeaderText="E" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
</telerik:RadAjaxPanel>

 <asp:ObjectDataSource  ID="gridData" runat="server"
                        SelectMethod="GetData"
                        SelectCountMethod="GetDataCount"
                        OnObjectCreating="dataObjectCreating"
                        TypeName="AreaListRadGrid">
</asp:ObjectDataSource>

<telerik:RadAjaxLoadingPanel runat="server" ID="radAjaxLoadingPanel">
        Loading please wait....
</telerik:RadAjaxLoadingPanel>

I've changed the names of columns and namespaces to something non-project specific, but the grid loads.

As it's in a Custom Control, it is instantiated as follows:

var view = (AreaListRadGrid)this.TemplateControl.LoadControl(".\\WebControls\\AreaListRadGrid.ascx");
view.DataSource = dataSet;
areaCenterMiddle.Controls.Add(view);
view.RadGrid.Rebind();

the dataSet variable is of type System.Data.DataSet.

So, when I run this website, the Rad Grid appears. I've got a grid with 4 rows, 3 of which are on page 1 and the final row is on page 2. initial radgrid after page 2 click When I click page 2, everything happens as expected. The styling for for page buttons change, and the rows from page 1 are removed, with the row from page 2 added to the grid. Great! What happens next is what I don't understand:

When page 1 is clicked again, the styling for the page 2 button dosn't change (so it's still as if it's clicked) and rows 2 and 3 appear on the grid, but the first row is the row which was on page 2.

re-visit to page 1

it seems as if page 2 is not clearing when page 1 is loaded, I'm not sure why or how this is, though. Anyone got any ideas to what I'm doing incorrectly?

Would really appreciate your help.

Cheers,

Rob

Accumulative answered 7/10, 2011 at 10:23 Comment(5)
Really well put together question. This is how questions should be.Migration
Any possibility of posting up the control itself? I started to setup a project to troubleshoot, but realized there's no way to if I can't instantiate the object.Rooseveltroost
You get this issue in all browser or only in any specific browser ?Organometallic
Can you try rebinding on grid page properties changed eventPitching
Does the problem go away if you take the grid out of the RadAjaxPanel? Also, since some time has passed, have you found a solution that you can post here to share with the community?Zimmerman
A
1

I'm sure you've got this figured out by now, but I'm wondering if this is a side effect of not setting the NeedDataSource property with the grid datasource?

add this to RadGrid control on the front end.

OnNeedDataSource="radGrid_NeedDataSource"

and handle it in code behind.

protected void radGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { view.RadGrid.DataSource = gridData; }

Allhallows answered 17/11, 2011 at 14:12 Comment(1)
I believe this should do the trick! NeedDataSource does the all magic you need.Kauppi
C
0

You do not need to provide the dataset to the grid when loaded. The dataset is retrieved using the DataSourceID you have set in design, when required.

Remove "view.DataSource = dataSet;" and the rebind function and everything should work as expected.

Chirpy answered 9/8, 2013 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.