Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telerik RadGrid Paging - Duplicate records and sticking buttons

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 radgridafter 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

like image 298
rjbell00 Avatar asked Oct 07 '11 10:10

rjbell00


1 Answers

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; }

like image 116
hardba11 Avatar answered Oct 30 '22 04:10

hardba11