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

[Solved] RadGrid Paging Problem in Webpart

9 Answers 460 Views
RadControls
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
dhananjay
Top achievements
Rank 1
dhananjay asked on 21 Mar 2007, 04:06 PM
Hi,
I am using RadGrid in Sample Webpart. With Paging enabled I am getting following problem Sequence of Step Performed :
1. When Click on Page no in Sequence [i.e 1,2,3,4...] Data Displayed is proper But Suppose
2. When i Clicked on Page 1 after page 3 i am getting Data Displayed of Page 3 on Page .

Note : this problem occur When i click on Page 1 after any other page.if i click Page 2 after any other page it work.

Can you please let me know what would be the problem


Sample code  Webpart:

using System;
using System.ComponentModel;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Xml.Serialization;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Utilities;

using Microsoft.SharePoint.WebPartPages;

using Telerik.WebControls;

using System.Data;

namespace Wachovia.CIBT.Portal.Internet.WebParts

{

/// <summary>

/// Description for SampleGrid.

/// </summary>

[DefaultProperty("Text"),

ToolboxData("<{0}:SampleGrid runat=server></{0}:SampleGrid>"),

XmlRoot(Namespace="Wachovia.CIBT.Portal.Internet.WebParts")]

public class SampleGrid : Microsoft.SharePoint.WebPartPages.WebPart

{

private const string defaultText = "";

private string text = defaultText;

RadGrid oGrid = new RadGrid();

[Browsable(true),

Category("Miscellaneous"),

DefaultValue(defaultText),

WebPartStorage(Storage.Personal),

FriendlyName("Text"),

Description("Text Property")]

public string Text

{

get

{

return text;

}

set

{

text = value;

}

}

/// <summary>

/// This method gets the custom tool parts for this Web Part by overriding the

/// GetToolParts method of the WebPart base class. You must implement

/// custom tool parts in a separate class that derives from

/// Microsoft.SharePoint.WebPartPages.ToolPart.

/// </summary>

///<returns>An array of references to ToolPart objects.</returns>

// public override ToolPart[] GetToolParts()

// {

// ToolPart[] toolparts = new ToolPart[2];

// WebPartToolPart wptp = new WebPartToolPart();

// CustomPropertyToolPart custom = new CustomPropertyToolPart();

// toolparts[0] = wptp;

// toolparts[1] = custom;

// return toolparts;

// }

/// <summary>

/// Render this Web Part to the output parameter specified.

/// </summary>

/// <param name="output"> The HTML writer to write out to </param>

protected override void RenderWebPart(HtmlTextWriter output)

{

this.oGrid.RenderControl(output);

}

protected override void CreateChildControls()

{

oGrid = new RadGrid();

oGrid.ID="oGrid";

oGrid.Attributes.Add("runat","server");

oGrid.AutoGenerateColumns=true;

oGrid.AllowPaging=true;

oGrid.PageSize=10;

oGrid.PagerStyle.Mode= GridPagerMode.NextPrevAndNumeric;

oGrid.PagerStyle.Position = GridPagerPosition.TopAndBottom;

oGrid.AllowMultiRowSelection=true;

oGrid.AllowMultiRowEdit=false;

oGrid.DataSource=GetDatavalues();

oGrid.DataBind();

this.Controls.Add(oGrid);

}

 

public DataTable GetDatavalues()

{

DataTable dt_ContentCategoryDetails = new DataTable("BusinessLine");

dt_ContentCategoryDetails.Columns.Add("ID",System.Type.GetType("System.String"));

dt_ContentCategoryDetails.Columns.Add("Description",System.Type.GetType("System.String"));

dt_ContentCategoryDetails.Columns.Add("ParentID",System.Type.GetType("System.String"));

DataRow dr_Details;

for(int i=0;i<=100;i++)

{

dr_Details = dt_ContentCategoryDetails.NewRow();

dr_Details["ID"]= i;

dr_Details["Description"] = "hello World" + i;

dt_ContentCategoryDetails.Rows.Add(dr_Details);

}

return dt_ContentCategoryDetails;

}

}

}


9 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 26 Mar 2007, 02:18 PM
Hello dhananjay,

It seems that you are using simple databinding for the Grid control and you are not handling the PageIndexChanged event (or at least you have not pasted the code). Please try using the NeedDataSource eventhandler for binding the RadGrid or handle the PageIndexChanged  event to navigate to the appropriate data.

Regards,
Steve
the telerik team

Instantly find answers to your questions at the new telerik Support Center
0
Ryan
Top achievements
Rank 1
answered on 12 Mar 2009, 08:51 PM
I'm having an issue very similar to this as well.

Here's my structure.

I have a SharePoint WebPart that get's an ASCX control and adds that to the page (to provide the maximum amount of control over the UI).

The grid is contained in the ASCX file. The gird uses the NeedDataSource method to handle rebinding.

It will let me advance to the second page, but then it after that, it won't let me go any further.
Same goes for sorting. It will let me sort asscending, but if I click it again, it just stays at asscending. I can swap to other columns, and it does the same thing.

There's a pattern here, but I'm not sure how to go about solving it. Imagine the clicks are following a list. You have step 1, step 2, and step 3.

When I click, and I'm at step 1, it will go to step 2. Click at step 2, it's like it goes back to 1, then progress to 2.

I'm thinking it has something to do with SharePoint adding the control 3-5 times each time it loads or gets an event.

Any help on this will be greatly appreciated.
0
Sebastian
Telerik team
answered on 13 Mar 2009, 08:59 AM
Hello Ryan,

Can you please verify that you do not have any DataBind() or Rebind() calls inside the OnInit/OnLoad/PreRender stages of the web part lifecycle? Such duplicate bindings can interfere with the advanced binding with NeedDataSource handling and cause these unexpected results on paging/sorting.

If the issue is elsewhere, please paste the code from your MOSS web part in this forum thread (using the 'Format Code Block' button at the top right corner of the forum editor) to investigate the matter further.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ryan
Top achievements
Rank 1
answered on 13 Mar 2009, 01:17 PM
Here's the need datasource method. Sorry for the spacing problem... :-(

 

/// <summary>

 

/// Called when the data grid loads or rebinds.

 

 

 

/// Needed for paging to function properly.

 

 

 

/// </summary>

 

 

 

/// <param name="source"></param>

 

 

 

/// <param name="e"></param>

 

 

 

protected void telerikGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

 

{

 

 

if (dataSource != null)

 

{

 

 

try

 

 

{

 

if (telerikGrid.EditItems.Count == 0)

 

{

tmrSyncTimer.Enabled =

 

true;

 

}

 

 

else

 

 

{

tmrSyncTimer.Enabled =

false;

 

}

 

 

DataTable tempTable = new DataTable();

 

 

 

string filter = getFilter();

 

 

 

if (!string.IsNullOrEmpty(filter))

 

{

tempTable = GetDataWithFilter(dataSource, filter);

 

 

if (tempTable.Rows.Count > 0)

 

{

telerikGrid.DataSource = tempTable;

}

 

 

else

 

 

{

blankifyGrid();

}

}

 

else

 

 

{

tempTable = GetData(dataSource);

 

if (tempTable.Rows.Count > 0)

 

{

telerikGrid.DataSource = tempTable;

}

 

 

else

 

 

{

blankifyGrid();

}

}

}

 

catch (Exception exc)

 

{

blankifyGrid();

}

}

 

 

else

 

 

{

blankifyGrid();

}

}

0
Ryan
Top achievements
Rank 1
answered on 13 Mar 2009, 02:58 PM
Here's something that might help you.

So, I just tried editing on page 2. If I select item 4 on page 2, then click edit, it jumps to item 4 on page 1. It's almost like the grid just isn't working in viewstate or something.... Speaking of that, I check to see if the grid has the enableviewstate property set to true, and it does. And no where on my page am I clearing the viewstate.
0
Ryan
Top achievements
Rank 1
answered on 13 Mar 2009, 03:00 PM
Another interesting thing is that I have a control on another page that utilizes telerik grid. It doesn't page, but it does sort. And it's not having the problems I'm having. I've checked out everything to see if it's set up differently, and it's an exact replica except for the fact it doesn't use the needdatasource method

Thanks so much for you help on this.
0
Sebastian
Telerik team
answered on 16 Mar 2009, 03:46 PM
Hi Ryan,

Your NeedDataSource event handler seems correctly defined. I assume that you stripped any DataBind()/Rebind() calls as discussed before.

Does moving the grid outside of the Sharepoint environment make a difference? I will also appreciate if you outline the differences between the two grid implementations (the one that works properly and the other that fails). They can help us pinpoint the cause of the erroneous behavior to address it.

Kind regards,
Sebastian
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
shaji
Top achievements
Rank 1
answered on 06 Oct 2009, 02:21 PM
HI  I have same issue with radgrid when  PagerStyle Mode is  Numeric then paging is working perfectly. 

when mode has "PrevNext"  then paging is not working pefectly..

 



 

 
0
Ryan
Top achievements
Rank 1
answered on 06 Oct 2009, 02:36 PM
Yeah... I found out what the solution was, but sorry I don't remember every detail...

On the action event (the event that's performed when anything happens in the grid), you need to set to the session, cache, cookie, etc... the current page index.

Then, override the paging event, and in there, before you page, set the current page index back to the grid...

It's a stupid solution, I know, but that's the only way I could get RAD Grid to preserve the index due to SharePoint recreating the grid each time the page even did a partial refresh, and then rad grid calling the load datasource method each time, refreshing the data in the grid, thus refreshing the page index... I hope that made since... 

Anyway, cache the page index, using any method you prefer, before any events happen on the grid, then set the index back to the grid on the paging event..
Tags
RadControls
Asked by
dhananjay
Top achievements
Rank 1
Answers by
Steve
Telerik team
Ryan
Top achievements
Rank 1
Sebastian
Telerik team
Ryan
Top achievements
Rank 1
shaji
Top achievements
Rank 1
Share this question
or