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

Pagination not working in RadGrid control

4 Answers 209 Views
Grid
This is a migrated thread and some comments may be shown as answers.
krishna
Top achievements
Rank 1
krishna asked on 14 Feb 2011, 05:38 PM
Hi,

      I am using a RadGrid control (Rad Controls for ASP.NET AJAX Q3 2009 NET20) to display data. I am not sure why my  control is not displaying data at all when I navigate from my first page. Below is the sample I am working with. Please help me understand what I am missing and how to rectify.

Thanks in advance.

Regards,
Krishna Chaduvula.

WEB.CONFIG (HTTP Handler)
<add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI" validate="false" />

ASPX Page:

<%

@ Page Language="VB" AutoEventWireup="false" CodeFile="testRadGrid.aspx.vb" Inherits="testRadGrid" %>

 

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

 

<

 

html xmlns="http://www.w3.org/1999/xhtml">

 

 

<

 

head runat="server">

 

 

<title></title>

 

 

</

 

head>

 

 

<

 

body>

 

 

<form id="form1" runat="server">

 

 

<div>

 

 

 

<asp:ScriptManager ID="ScriptManager1" runat="server">

 

 

</asp:ScriptManager>

 

 

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

 

<AjaxSettings>

 

 

<telerik:AjaxSetting AjaxControlID="grdPayStatements">

 

 

<UpdatedControls>

 

 

<telerik:AjaxUpdatedControl ControlID="grdPayStatements" />

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

 

</AjaxSettings>

 

 

</telerik:RadAjaxManager>

 

 

<telerik:RadGrid runat="server" ID="grdPayStatements" AllowPaging="True"

 

 

 

AutoGenerateColumns="False" GridLines="None" GroupingEnabled="False"

 

 

 

HorizontalAlign="Center" >

 

 

<MasterTableView>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridHyperLinkColumn AllowFiltering="False"

 

 

 

DataNavigateUrlFields="SEQNR" DataNavigateUrlFormatString="test.aspx?id={0}"

 

 

 

DataTextField="PayDate" HeaderText="Pay Date" UniqueName="column1">

 

 

</telerik:GridHyperLinkColumn>

 

 

<telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False"

 

 

 

DataField="TotalGross" DefaultInsertValue="" HeaderText="Total Gross"

 

 

 

UniqueName="column2">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False"

 

 

 

DataField="NetPay" DefaultInsertValue="" HeaderText="Net Pay"

 

 

 

UniqueName="column3">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False"

 

 

 

DataField="SEQNR" DefaultInsertValue="" HeaderText="SEQNR" UniqueName="column"

 

 

 

Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

 

</div>

 

 

</form>

 

 

</

 

body>

 

 

</

 

html>


CODE BEHIND

 

 

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

 

 

 

If Not Page.IsPostBack Then

 

 

 

 

 

 

 

LoadData()

 

 

 

End If

 

 

 

 

 

 

 

 

 

End Sub

 

 

 

 

 

 

 

 

 

Private Sub LoadData()

 

 

 

 

Dim dt As DataTable = New DataTable()

 

 

dt.Columns.Add(

 

"SEQNR")

 

 

dt.Columns.Add(

 

"PayDate")

 

 

dt.Columns.Add(

 

"TotalGross")

 

 

dt.Columns.Add(

 

"NetPay")

 

 

 

 

Dim t As Double = 0

 

 

 

 

For i As Integer = 0 To 29

 

 

 

 

Dim dr As DataRow = dt.NewRow()

 

 

dr(

 

"PayDate") = DateTime.Today().AddDays(i)

 

 

dr(

 

"NetPay") = 2000

 

 

t += 2000

 

dr(

 

"TotalGross") = t

 

 

dr(

 

"SEQNR") = i + 1

 

 

dt.Rows.Add(dr)

 

 

 

Next

 

 

 

 

 

 

 

grdPayStatements.DataSource = dt

 

grdPayStatements.DataBind()

 

 

 

End Sub

 

 

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 14 Feb 2011, 10:59 PM
Hi Krishna,

Note that simple data-binding through the DataBind() method can be used in simple scenarios which does not require complex operations like paging insert/delete/update, grouping, hierarchy relations, etc. Also keep in mind that if you choose simple data-binding, you will need to assign data-source and rebind the grid after each operation same like MS DataGrid.


If you are using advanced features for grid, a better option will be using AdvancedDataBinding technique as shown in the demo below.
Advanced Data Binding

Best wishes,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
krishna
Top achievements
Rank 1
answered on 14 Feb 2011, 11:55 PM
Pavlina,

  Thanx for the quick response. The link you specified in your post looks like it is broken. So did you meant to say that I have to use advanced Data bindings to incorporate paging?

Thank you.

Regards,
Krishna Chaduvula
0
krishna
Top achievements
Rank 1
answered on 15 Feb 2011, 08:36 PM

Issue with the RadGrid control for Paging is that when the Page index changed, there was a post back event and the datasource that I set earlier was no longer available, So my Solution to this is to add the Datasource to the session and in the "Page_IndexChanged" event, get the datasource from the session and rebind it to the control. Below is the code I had to add:

 

 

Protected

 

 

 

Sub grdPayStatements_PageIndexChanged(ByVal source As Object, ByVal e As Telerik.Web.UI.GridPageChangedEventArgs) Handles

grdPayStatements.PageIndexChanged

  

 

 

Dim dtPayHistory As New

DataTable

 

 

 

 

 

If Not Session("dtPayHistory") Is Nothing

Then

 

 

dtPayHistory = CType(Session("dtPayHistory"

), DataTable)

RadGrid1.Dispose() 

RadGrid1.DataSource = dtPayHistory

 

RadGrid1.DataBind() 

RadGrid1.CurrentPageIndex = e.NewPageIndex

 End If

 

 

End

Sub

 

 

0
Pavlina
Telerik team
answered on 16 Feb 2011, 10:55 AM
Hi Krishna,

Please excuse me for the broken link. Here is the correct one:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx

Regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
krishna
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
krishna
Top achievements
Rank 1
Share this question
or