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 <a 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.