RadGrid on Page event, only appear 1 row when should be 20

2 Answers 72 Views
Ajax AjaxPanel Grid
Miguel
Top achievements
Rank 1
Miguel asked on 26 May 2022, 02:50 PM

Hi,

 

When currentpageindex = 1, grid retrieve only 1 row but if currentPageIndex <> 1 returns the rows excepted.

 

I ajaxified the grid.

        <telerik:RadAjaxManager ClientEvents-OnResponseEnd="AjaxResponseEnd" ID="ramRepostasConsentimentos" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rgListagem">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rgListagem" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>

 

I set pageSize to 20 and i am using custom paging.

                    <telerik:RadGrid ID="rgListagem" runat="server" RenderMode="Lightweight" Width="100%" CellSpacing="0" BorderWidth="0" GridLines="None" PageSize="20" EnableViewState="true">
                        <MasterTableView TableLayout="Fixed" AutoGenerateColumns="false" AllowCustomPaging="true" AllowPaging="true" PageSize="20" ShowHeadersWhenNoRecords="true">
                            <Columns>
                                <telerik:GridBoundColumn DataField="numMec" HeaderText="Nº Mec.">
                                    <HeaderStyle CssClass="TextIndent" Width="100px" />
                                    <ItemStyle CssClass="TextIndentRight" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="descColaborador" HeaderText="Colaborador">
                                    <HeaderStyle CssClass="TextIndent" Width="30%" />
                                    <ItemStyle CssClass="TextIndent" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="descConsentimentoInformado" HeaderText="Consentimento Informado">
                                    <HeaderStyle CssClass="TextIndent" Width="70%" />
                                    <ItemStyle CssClass="TextIndent" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="consentimento" HeaderText="Consentimento">
                                    <HeaderStyle CssClass="TextIndent" Width="100px" />
                                    <ItemStyle CssClass="TextIndent" />
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                        <HeaderStyle VerticalAlign="Middle" HorizontalAlign="Left" />
                        <AlternatingItemStyle CssClass="TLookUpsRowBlue" VerticalAlign="Middle" />
                        <ItemStyle CssClass="TLookUpsRowGrey" VerticalAlign="Middle" />
                        <PagerStyle Mode="NextPrevAndNumeric" Position="Bottom" PageSizeControlType="None" PagerTextFormat="{4} Pag. {0} de {1}, Registos {2} até {3} de {5}." CssClass="TLookupsFooter" PageButtonCount="5" />
                        <ClientSettings>
                            <Scrolling UseStaticHeaders="true" AllowScroll="true" />
                        </ClientSettings>
                    </telerik:RadGrid>

 

I am using OnNeedDataSourceEvent.


Protected Sub rgListagem_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgListagem.NeedDataSource
        Dim SqlCmd As SqlCommand, SqlDa As SqlDataAdapter, Data As DataTable

            SqlCmd = fGetClsFunc.fGetCommand(StoredProcedureName, CommandType.StoredProcedure, True)
            SqlCmd.Parameters("@strAction").Value = "R"
            SqlCmd.Parameters("@skip").Value = rgListagem.MasterTableView.CurrentPageIndex * rgListagem.MasterTableView.PageSize
            SqlCmd.Parameters("@take").Value = rgListagem.MasterTableView.PageSize + 
rgListagem.MasterTableView.CurrentPageIndex * rgListagem.MasterTableView.PageSize

            SqlDa = New SqlDataAdapter(SqlCmd)
            Data = New DataTable()

            SqlDa.Fill(Data)


        rgListagem.DataSource = Data
        rgListagem.VirtualItemCount = SqlCmd.Parameters("@Contador").Value
    End Sub

 

if CurrentPageIndex = 1, Query returns 20 rows but only appear one.

2 Answers, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 31 May 2022, 07:25 AM

Hi Miguel,

I suggest that you put a BreakPoint in the NeedDataSource event, right before setting the DataSource, run the Project in debug mode and use the QuickWatch to inspect the "Data" variable. 

That will show you if the SQL Query you have to query for data is working as intended. You can also try and test the query directly with the SQL Server and see if that returns the expected results.

 

We have a Custom Paging online example that uses Object Collections, however, the logic returns the correct amount of data and the Grid will display that. Please check out the Custom Paging demo and inspect its source code to see how it was implemented.

 

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Mukesh
Top achievements
Rank 1
Iron
answered on 31 May 2022, 08:12 AM

Hello  Miguel,

Please use below parameters to pass in your store procedure to get records based on radgrid pagination.

SqlCmd.Parameters("@PageNumber").Value = rgGrid.CurrentPageIndex * rgGrid.PageSize;
SqlCmd.Parameters("@RowsPerPage").Value = rgGrid.PageSize;

Apply below logic in Store procedure.

SELECT * from TableName ORDER BY ID ASC OFFSET @PageNumber ROWS   FETCH NEXT @RowsPerPage ROWS ONLY

Hope this will help you.

Thanks,

Mukesh Prajapati

Miguel
Top achievements
Rank 1
commented on 31 May 2022, 08:56 AM

Hi, 

I cant use OFFSET because of my sql server version.

I debugged and query returns 20 rows has excepted but when grid rendered only appear one...

It only happens when selected page index equals one.

Miguel
Top achievements
Rank 1
commented on 31 May 2022, 09:09 AM

Okay, I fix the bug.

Query returns 21 rows when current page index equals one and I didn't realize it.

Thanks for your help

Tags
Ajax AjaxPanel Grid
Asked by
Miguel
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Mukesh
Top achievements
Rank 1
Iron
Share this question
or