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

Community
  • 1
  • 1
rjbell00
  • 107
  • 7
  • 1
    Really well put together question. This is how questions should be. – James Johnson Oct 07 '11 at 13:55
  • 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. – KreepN Oct 11 '11 at 03:04
  • You get this issue in all browser or only in any specific browser ? – Jayesh Goyani Oct 13 '11 at 05:55
  • Can you try rebinding on grid page properties changed event – Syam Oct 19 '11 at 06:07
  • 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? – Mike Guthrie Apr 05 '12 at 20:03

2 Answers2

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

hardba11
  • 1,478
  • 15
  • 27
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.

Jack Ward
  • 61
  • 1
  • 7