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

linq programatic loading radgrid and paging

6 Answers 308 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 2
Darren asked on 15 Jun 2009, 10:17 AM
Hi there,

I'm loading my Radgrid programmatically:

        if (!IsPostBack)
        {

        var gridDS = from statements in db.tblEstatementDetails
                     where statements.EpageStatementId == Convert.ToInt64(cardType)
                     join card in db.tblEpageStatements on statements.EpageStatementId equals card.EpageStatementId
                     select new
                     {
                         statements.EstatementDetailId,
                         card.CardName,
                     };


        RadGrid1.DataSource = gridDS;
        RadGrid1.AllowPaging = true;
        RadGrid1.DataBind();

}

Umm but when the records exceed 10 then the pagination options are available which is great. However when I click next, or previous or even try to expand my record list from '10' to say '20' then the grid just empties as if the Radgrid is not databound any more.

6 Answers, 1 is accepted

Sort by
0
Accepted
Pavlina
Telerik team
answered on 15 Jun 2009, 11:35 AM
Hi Darren,

Please note that simple data-binding through the DataBind() method can be used in simple cases when you do not require the grid to perform complex operations such as paging.
For advanced features such as paging, grouping, sorting etc., please bind your grid with data through the NeedDataSource event. When using the NeedDataSource event, RadGrid can automatically accommodate the appropriate database operations without the need for you explicitly handle any sorting, paging, grouping, and so on.

I hope this helps.

Sincerely yours,

Pavlina
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
Nat
Top achievements
Rank 1
answered on 24 Sep 2009, 06:25 PM
Hi Telerik team,

In my case, I did bind RadGrid through NeedDataSource event because the number of record pulled on RadGrid is driven by different RadTabStrip click.  I had the Mode of PagerStyle set to "NextPrevAndNumeric";  The grid did display various pages based on the number buttons clicked. but the previous ( < ) and next button( > ) never seem to work?  Do you know what I have missed?
Thanks,
0
wdudek
Top achievements
Rank 1
answered on 24 Sep 2009, 08:49 PM
You are going to do your binding in the need data source event and use the skip and take methods to get the right data.

var v = (from o in sourceData
             select o).Skip(grid.CurrentPageIndex * grid.PageSize).Take(grid.PageSize);

grid.DataSource = v;


you will also need to set the VirtualItem count on the grid so that it knows how to correctly setup the paging.
0
Nat
Top achievements
Rank 1
answered on 25 Sep 2009, 02:10 PM
Hi,
Thanks for your quick reply.
I am not familiar with the syntax of  "(from o in sourceData select o).Skip(grid.CurrentPageIndex * grid.PageSize).Take(grid.PageSize)" ?   How do I change my RadGrid datasource from a  'select' DataObjectMethod to the query above?
Thanks,
0
Nat
Top achievements
Rank 1
answered on 25 Sep 2009, 06:20 PM
Okay, I got the iterated query:

List

 

<Order> list  = new List<Order>();

 

list = GetOrders(empID);

 

 

var query = (from o in list select o).Skip(RadGrid1.CurrentPageIndex * RadGrid1.PageSize).Take(RadGrid1.PageSize);

 

RadGrid1.DataSource = query;

 

 

 

 

 


I placed the above code on the NeedDataSource event, it shows only the first page which has 10 records as is defined in PageSize.  But when I clicked on the next (number) button, the grid does not display any record even though it a total of 246 records? Where should I put the above code?

0
wdudek
Top achievements
Rank 1
answered on 28 Sep 2009, 11:31 AM
You also need to set the VirtualItemCount property of the grid to the total number of records at some point, such as on the initial databind or page load
Tags
Grid
Asked by
Darren
Top achievements
Rank 2
Answers by
Pavlina
Telerik team
Nat
Top achievements
Rank 1
wdudek
Top achievements
Rank 1
Share this question
or