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

[Solved] How RadGrid Paging works?

3 Answers 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Søren Hartig
Top achievements
Rank 2
Søren Hartig asked on 28 Nov 2009, 02:17 PM
Hi all,

I'm kind'a new to the Telerik components (work with them everyday but in basic stuff), because we (company) used it for more than 2 years now, I decided to use them (extensively) in a new project I have in hands, and even reading the entire Paging content inside the Grid section for more than 3 times now, I can't find what I'm doing wrong.

I have a Grid control that looks like this:

<telerik:RadGrid ID="gvResult" CssClass="tblQuery queryWindow maxSize ui-widget-content" 
        runat="server" GridLines="None" CellPadding="15" AutoGenerateColumns="False" 
        PageSize="25" AllowPaging="True" OnRowDataBound="gvResult_RowDataBound" onpageindexchanging="gvResult_PageIndexChanging" 
        Skin="Web20" onneeddatasource="gvResult_NeedDataSource"
        <MasterTableView> 
            <NoRecordsTemplate> 
                Hummmm, there is nothing to show, the search result in absolutly nothing! Maybe you want to <href="javascript:history.back(-1);">go back</a> and search again with other parameters? 
            </NoRecordsTemplate> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
        </MasterTableView> 
        <HeaderStyle HorizontalAlign="Left" /> 
        <ItemStyle HorizontalAlign="Left" /> 
        <AlternatingItemStyle HorizontalAlign="Left" /> 
    </telerik:RadGrid> 

simple right ? ...

and on code behind on PageLoad I populate the Data
protected void Page_Load(object sender, EventArgs e) 
    if (!IsPostBack) 
        PopulateData(); 
}

where inside the PopulateData method I call a method that creates a DataTable and attach it to the Grid DataSource.

The DataTable is created with static columns and dynamic, so I never know the column size, only on runtime.

My CreateSource method dos this in summary:

1 - Creates a new DataTable object
2 - Creates 5 DataColumns (statict columns) and adds them into the DataTable object
3 - Loops through all dynamic columns and adds the same way

4 - For each Business Object in my Collection I add the Data into a DataRow and attach it to the DataTable.Rows Collection

5 - Foreach DataColumn in DataTable.Columns I Bound the DataFields, GridCheckBoxColumn, GridHyperlinkColumn and GridBoundColumn respectivly by my Business Object type

6 - Keep this DataTable object into a Session Variable
7 - RadGrid.DataSource = myDataTable

that works fine, and it is show lovely on the rendered page... but! (there's always a but) :-( 
I can't work with the pagging, when I press any other page I do not get my data, but the Column Type .ToString() :-/

Reading the help I created a method (NeedDataSource) and added this code into it:
protected void gvResult_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    if (HttpContext.Current.Session["EDSWebSearch-SearchReturn-DataTable"] != null
    { 
        gvResult.DataSource = (DataTable)HttpContext.Current.Session["EDSWebSearch-SearchReturn-DataTable"]; 
    } 
    else 
    { 
        edsDebug.Write("Session Expired, redirecting to Start page"); 
        Response.Redirect("default.aspx" + Request.Url.Query); 
    } 

The DataTable contains all items I need, what should I do here?


screenshots attached, screencast here: (35 sec: 1,35Mb) http://bit.ly/6xxxMV

Thank you,
// Bruno Alexandre, using Soren's account.





3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 30 Nov 2009, 11:58 AM
Hi Søren,

Our system shows that you have opened a support ticket, regarding this forum post.
To aviod duplicate posts, please refer to the support ticket for further details.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Søren Hartig
Top achievements
Rank 2
answered on 30 Nov 2009, 02:36 PM
I prefer to use the forum first so anyone can view the result, someone might have the same problem as I do.

It will make easier to search and find resolved examples.
0
Yavor
Telerik team
answered on 01 Dec 2009, 12:34 PM
Hello Søren,

For the time being, until the issue is resolved, it is best to use the support ticketing system. Once done, you can feel free to post the solution to the community, so that other people can benefit from it as well.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Søren Hartig
Top achievements
Rank 2
Answers by
Yavor
Telerik team
Søren Hartig
Top achievements
Rank 2
Share this question
or