Search code examples
vb.nettelerik-grid

Telerik radgrid pagination issue - next page, prev page, first page and last page not working


I have tried everything I could possibly gather from what I read (from adding a need source to adding pageindexchanged, etc., but still am not able to figure it out... any assistance would be gratefully lapped up...

following is my code...

<asp:UpdatePanel runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <telerik:RadAjaxManager ID="ram1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="ajaxtimer1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgNewsFeed" LoadingPanelID="LoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

    <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" />

      <telerik:RadGrid ID="rg1" runat="server" ShowStatusBar="True" AllowPaging="true" >
         <MasterTableView AutoGenerateColumns="False" TableLayout="Fixed">
            <Columns>
                <telerik:GridBoundColumn DataField="CommentSubject" HeaderText="Subject" />
                <telerik:GridHyperLinkColumn DataTextField="CommentText" DataTextFormatString="{0}" DataNavigateUrlFormatString="~/Views/m.aspx?pEntityID={0}" 
                    DataNavigateUrlFields="CmtTextID" HeaderText="Details" UniqueName="gbcCommentText" />
                <telerik:GridBoundColumn DataField="EntityFundName" HeaderText="Entity/Fund" />
                <telerik:GridBoundColumn DataField="EnteredBy" HeaderText="Entered by" />
                <telerik:GridBoundColumn DataField="CommentAge" HeaderText="Last Updated" />
            </Columns>
         </MasterTableView>
    </telerik:RadGrid>

    <asp:Panel ID="Panel1" runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="3000">
        </asp:Timer>
    </asp:Panel>

    </ContentTemplate>
</asp:UpdatePanel>

Code behind

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

        rg1.DataSource = dt 'some datatable
        rg1.DataBind()

End Sub

Public Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
        rg1.DataSource = dt 'some datatable
        System.Threading.Thread.Sleep(500)
End Sub

Protected Sub rgLeoNotesNewsFeed_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgLeoNotesNewsFeed.NeedDataSource


    rg1.DataSource = dt 'some datatable


End Sub

Solution

  • First off, I'd replace asp:UpdatePanel with telerik:RadAjaxPanel. I had to use telerik components for a while and did not have the best time. If you're using radgrid and aiming to use updatepanel with it, use a corresponding telerik component such as telerik:RadAjaxPanel. This way you will experience less issues.

    Second, I'm a bit confused with the following part

    <telerik:AjaxSetting AjaxControlID="ajaxtimer1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="rgNewsFeed" LoadingPanelID="LoadingPanel1" />
        </UpdatedControls>
    </telerik:AjaxSetting>
    

    You don't seem to have any controls with the IDs rgNewsFeed and ajaxtimer1. You're basically saying RadAjaxManager to update rgNewsFeed on ajaxtimer1 update.

    Shouldn't this be like

    <telerik:AjaxSetting AjaxControlID="Timer1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="rg1" LoadingPanelID="LoadingPanel1" />
        </UpdatedControls>
    </telerik:AjaxSetting>
    

    Also, you need to ajaxify your grid like that

    <telerik:AjaxSetting AjaxControlID="rg1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="rg1"></telerik:AjaxUpdatedControl>
        </UpdatedControls>
    </telerik:AjaxSetting>
    

    Not sure if your issue is related to those, but give it a try and see if that works.

    EDIT

    Protected Sub OnLoad(sender As Object, e As System.EventArgs) Handles Me.Load
            rg1.DataSource = dt 'some datatable
            rg1.DataBind()
    End Sub
    

    I think you should set the datasource on each call but call DataBind method only if it's not a postback. Try the following.

    Protected Sub OnLoad(sender As Object, e As System.EventArgs) Handles Me.Load
        rg1.DataSource = dt 'some datatable
        If Not IsPostBack Then
            rg1.DataBind()
        End If
    End Sub