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

Sorting and Paging in Grid not working

9 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
parimal
Top achievements
Rank 1
parimal asked on 13 Jun 2008, 02:21 AM
Hi,
I have a Radgrid which i bound with a data table. The data is shown properly in the grid. Now when i click on Page values of grid, everything works fine. Now if I sort the column the Grid shows No Records for display. If I sort the Grid First, sorting happens but after Page click, the Grid again shows No Records for display.

So each action works fine individually but not if one action is done after another i.e. Paging-->Sorting or Sorting-->Paging, Grid shows No Record for display.
In Code behind, the Grid Datasource always shows Data.

Need help on urgent basis.

regards,

PN

Code:
ASPX PAGE:  
---------------  
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
            <telerik:RadGrid ID="RadGrid1" Skin="Office2007" Width="97%" AllowSorting="True" 
             PageSize="15" ShowFooter="True" AllowPaging="True" AllowMultiRowSelection="True" runat="server" Gridlines="None"   
             OnNeedDataSource="RadGrid1_NeedDataSource">  
              <MasterTableView Width="100%" /> 
              <PagerStyle Mode="NextPrevAndNumeric" /> 
            </telerik:RadGrid> 
--------------------------------------------------------------------------  
 
Code Behind:  
--------------  
  protected void Page_Load(object sender, EventArgs e)  
        {  
 
        }  
        protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            DataTable dt=null;  
            dt=GetDataTable();  
            if(dt!=null)  
            RadGrid1.DataSource = dt;  
 
        }  
        private DataTable GetDataTable()  
        {  
            DataTable dt = null;  
            DataSet dsResults = Utility.SearchCategoryCards("Digital", Session["UserCompanyCode"].ToString());  
            if (dsResults != null && dsResults.Tables.Count > 0 && dsResults.Tables[0].Rows.Count > 0)  
            {  
                dt = dsResults.Tables[0]; ;  
                return dt;  
            }  
            else  
            {  
                return dt;  
            }  
        } 

9 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 13 Jun 2008, 07:21 AM
Hi parimal,

Can you please debug if the DataTable set to the Grid DataSource contains the necessary records on each problematic action? Just put a breakpoint on the line where you set the Grid DataSource in NeedDataSource and let us know about the result. The Grid displays data only when you set the proper source.

You can also look at the online demos, where the paging and sorting function properly together:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/GeneralFeatures/Paging/DefaultCS.aspx

I hope this helps!

Best wishes,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
parimal
Top achievements
Rank 1
answered on 13 Jun 2008, 07:40 AM
Hi,

ALways Data is available in the DataTable for any Paging or Sorting Action. The issue is still there.

Can you try the same code as sample and test from your end? It will be a great help..

regards,
PN
0
Vlad
Telerik team
answered on 13 Jun 2008, 11:16 AM
Hello parimal,

Similar code is used in this example:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/NeedDataSource/DefaultCS.aspx

Can you try to debug the code at your end and let us know if NeedDataSource is executed on paging/sorting post-backs?

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
parimal
Top achievements
Rank 1
answered on 16 Jun 2008, 03:50 AM
Hi,

The NeedDatasource event is called during Paging and Sorting events and the Grid Data table always have data in this event. But still Grid shows "No records to display" if Paging is performed after Sorting or Sorting is performed after Paging.

Need help,

PN
0
Vlad
Telerik team
answered on 16 Jun 2008, 07:48 AM
Hello parimal,

I suggest you to open a support ticket and send us small example where this can be reproduced. I will review your scenario and I will get back to you with more info.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jyoti
Top achievements
Rank 1
answered on 30 Jul 2008, 12:18 PM
HI
I am also having the same sorting and paging problem please sort it out.
0
Vladimir
Top achievements
Rank 1
answered on 30 Jul 2008, 07:21 PM
Hi,

Can you show us an example which demonstrates your case?

Vlad
0
Jyoti
Top achievements
Rank 1
answered on 31 Jul 2008, 10:34 AM
Hi,
I am giving you code and also sending you query for sorting and paging please review it and see whats the problem

/// <summary>

/// Sort Grid View

/// </summary>

///<param name="sortOrder"></param>

///<param name="sqlSortExpression"></param>

/// <returns></returns>

private void RadGrid_TextListEditor_SortDataBind(string sqlSortExpression, string sortOrder)

{

List<TextList> textList;

// sqlSortExpression += " " + sortExpression;

textList =

TextListBLL.GetTextLists(textListId, RadGrid_TextListEditor.CurrentPageIndex, RadGrid_TextListEditor.PageSize, sqlSortExpression, sortOrder);

RadGrid_TextListEditor.VirtualItemCount =

TextListBLL.GetTextListsCount(textListId);

RadGrid_TextListEditor.DataSource = textList;

RadGrid_TextListEditor.DataBind();

//adGrid_TextListEditor.Rebind();

}

/// <summary>

/// Bind Grid View

/// </summary>

private void RadGrid_TextListEditor_DataBind()

{

List<TextList> textList;

string sqlSortExpression = "";

if (RadGrid_TextListEditor.MasterTableView.SortExpressions.Count != 0)

{

sqlSortExpression = RadGrid_TextListEditor.MasterTableView.SortExpressions[0].ToString();

}

textList =

TextListBLL.GetTextLists(textListId, RadGrid_TextListEditor.CurrentPageIndex, RadGrid_TextListEditor.PageSize, sqlSortExpression,"");

RadGrid_TextListEditor.VirtualItemCount =

TextListBLL.GetTextListsCount(textListId);

RadGrid_TextListEditor.DataSource = textList;

RadGrid_TextListEditor.DataBind();

//RadGrid_TextListEditor.Rebind();

}



/// <summary>

/// Grid View Paging

/// </summary>

protected void RadGrid_TextListEditor_PageIndexChanged(object source, GridPageChangedEventArgs e)

{

RadGrid_TextListEditor.CurrentPageIndex = e.NewPageIndex;

RadGrid_TextListEditor_DataBind();

}

/// <summary>

/// Grid View Sort Command,Sorting

/// </summary>

/// <returns></returns>

protected void RadGrid_TextListEditor_SortCommand(object source, GridSortCommandEventArgs e)

{

string sortExpression = "";

if (RadGrid_TextListEditor.MasterTableView.SortExpressions.Count == 1)

{

switch (RadGrid_TextListEditor.MasterTableView.SortExpressions[0].SortOrder)

{

case GridSortOrder.Ascending:

sortExpression =

"DESC";

break;

case GridSortOrder.Descending:

sortExpression =

"ASC";

break;

}

}

RadGrid_TextListEditor_SortDataBind(e.SortExpression,sortExpression.ToString());

}



string query = @"

WITH TextList AS

(

SELECT

ROW_NUMBER() OVER (ORDER BY "

+ sortExpression + @") AS RowNumber,

tl.*

FROM

(

SELECT dt.Id,

dt.Alias,sl.Culture AS Language,dt.Text,dt.SystemLanguageId

FROM

DocGen_Texts dt

LEFT OUTER JOIN

Core_SystemLanguages sl

ON dt.SystemLanguageId=sl.Id

WHERE dt.TextListId=@Id

) tl

)"

;

string pagingClause = " SELECT * FROM TextList WHERE RowNumber BETWEEN ((@CurrentPageIndex * @PageSize)+1) AND ((@CurrentPageIndex * @PageSize) + @PageSize)";

string queryPaged = query + pagingClause;

0
Angie
Top achievements
Rank 1
answered on 31 Jul 2008, 07:37 PM
Hey Jyoti.  I was having the same problem this morning, using custom paging.  If you are not using the latest version of telerik (from 6/19/08, I think), try upgrading to that version.

It solved my problem.

Here is the thread that talks about it:
http://www.telerik.com/community/forums/thread/b311D-bbkate.aspx

Hope that helps.
Tags
Grid
Asked by
parimal
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
parimal
Top achievements
Rank 1
Vlad
Telerik team
Jyoti
Top achievements
Rank 1
Vladimir
Top achievements
Rank 1
Angie
Top achievements
Rank 1
Share this question
or