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

paging for radgrid inside radpanelbar

5 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Duy
Top achievements
Rank 1
Duy asked on 12 Jun 2013, 02:23 PM
i have a radpanelbar that contains a radgrid. i have turned on allowpaging but not sure how to make the paging works. every time when i click on page 2 or next page or any page, my grid disappear. so i put in OnNeedDataSource but it only refreshes my grid and not going to the right page. any idea how to do this? thank you
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView DataKeyNames="id" AutoGenerateColumns="false" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"
                                                AlternatingItemStyle-HorizontalAlign="Center" >
                                                <Columns>
 <telerik:GridBoundColumn DataField="id" HeaderText="id" UniqueName="id" ReadOnly="true" />
</Columns>
                                            </MasterTableView>
                                            <PagerStyle Mode="NextPrevAndNumeric" />
                                        </telerik:RadGrid>




5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 12 Jun 2013, 02:39 PM
Hi Duy,

Please have a look at this example i tried.Check if this helps,or else provide your code for further verification.

ASPX:
<telerik:RadPanelBar runat="server">
           <Items>
               <telerik:RadPanelItem runat="server" Text="Root RadPanelItem1">
                   <Items>
                       <telerik:RadPanelItem runat="server" Value="PanelItem1">
                           <ItemTemplate>
                               <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" DataSourceID="SqlDataSource2">
                                   <MasterTableView DataKeyNames="id" AutoGenerateColumns="false" HeaderStyle-HorizontalAlign="Center"
                                       ItemStyle-HorizontalAlign="Center" AlternatingItemStyle-HorizontalAlign="Center">
                                       <Columns>
                                           <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" UniqueName="CustomerID"
                                               ReadOnly="true" />
                                       </Columns>
                                   </MasterTableView>
                                   <PagerStyle Mode="NextPrevAndNumeric" />
                               </telerik:RadGrid>
                           </ItemTemplate>
                       </telerik:RadPanelItem>
                   </Items>
               </telerik:RadPanelItem>
           </Items>
       </telerik:RadPanelBar>
Thanks
Princy
0
Duy
Top achievements
Rank 1
answered on 12 Jun 2013, 02:46 PM
below is what i have but it doesn't do paging. all it does is just refresh the grid and stay on page 1


<
telerik:RadPanelBar ID="RadPanelBar1" ExpandMode="MultipleExpandedItems" Width="100%" runat="server">
        <Items>
            <telerik:RadPanelItem  Expanded="true" Text="Step 1:"runat="server" Selected="true">
                <Items>
                    <telerik:RadPanelItem Value="New" runat="server">
                        <ItemTemplate>
                <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" OnPageIndexChanged="RadGrid1_PageIndexChanged">
                                            <MasterTableView DataKeyNames="ID" AutoGenerateColumns="false" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"
                                                AlternatingItemStyle-HorizontalAlign="Center" >
                                                <Columns>
                                                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" ReadOnly="true" />
                                                    <telerik:GridBoundColumn DataField="Date" HeaderText="Date" UniqueName="Date" DataFormatString="{0:MM/dd/yyyy}" />
                                                </Columns>
                                            </MasterTableView>
                                            <PagerStyle Mode="NextPrevAndNumeric" />
                                        </telerik:RadGrid>
                <asp:button id="btn" runat="server" text="get date" onclick="btn_Click"/>
            </ItemTemplate>
        </items>
    </telerik:RadPanelItem>
    </items>
</telerik:RadPanelBar>
 
Protected Sub btn_Click(sender As Object, e As EventArgs)
    Dim RadGrid1 As RadGrid = DirectCast(RPB_NewDocument.FindItemByValue("New").FindControl("RadGrid1"), RadGrid)
    radgrid1.datasource=getdate()
    radgrid1.databind()
end sub
 
 
Protected Sub RadGrid1_PageIndexChanged(sender As Object, e As GridPageChangedEventArgs)
    Dim RadGrid1 As RadGrid = DirectCast(RPB_NewDocument.FindItemByValue("New").FindControl("RadGrid1"), RadGrid)
    radgrid1.datasource=getdate()
    radgrid1.databind()
end sub
0
Princy
Top achievements
Rank 1
answered on 13 Jun 2013, 04:30 AM
Hi,
The code is working fine at my side.May I ask,Your RadPanelBar ID="RadPanelBar1",then how did you access it in the code behind with
"RPB_NewDocument" name?

Here I,m pasting the code of what i have tried.

ASPX:
<telerik:RadPanelBar ID="RadPanelBar1" ExpandMode="MultipleExpandedItems" Width="100%"
    runat="server">
    <Items>
        <telerik:RadPanelItem Expanded="true" Text="Step1" runat="server" Selected="true">
            <Items>
                <telerik:RadPanelItem Value="New" runat="server">
                    <ItemTemplate>
                        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" OnPageIndexChanged="RadGrid1_PageIndexChanged">
                            <MasterTableView AutoGenerateColumns="false" HeaderStyle-HorizontalAlign="Center"
                                DataSourceID="SqlDataSource2" ItemStyle-HorizontalAlign="Center" AlternatingItemStyle-HorizontalAlign="Center">
                                <Columns>
                                    <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" UniqueName="OrderID"
                                        ReadOnly="true" />
                                    <telerik:GridBoundColumn DataField="OrderDate" HeaderText="OrderDate" UniqueName="OrderDate"
                                        DataFormatString="{0:MM/dd/yyyy}" />
                                </Columns>
                            </MasterTableView>
                            <PagerStyle Mode="NextPrevAndNumeric" />
                        </telerik:RadGrid>
                        <asp:Button ID="btn" runat="server" Text="Get Data" OnClick="btn_Click" />
                    </ItemTemplate>
                </telerik:RadPanelItem>
            </Items>
        </telerik:RadPanelItem>
    </Items>
</telerik:RadPanelBar>

VB:
Protected Sub btn_Click(sender As Object, e As EventArgs)
    Dim RadGrid1 As RadGrid = DirectCast(RadPanelBar1.FindItemByValue("New").FindControl("RadGrid1"), RadGrid)
    RadGrid1.DataBind()
End Sub

Thanks,
Princy
0
Duy
Top achievements
Rank 1
answered on 13 Jun 2013, 01:11 PM
Hi Princy, thank you for the reply, i forgot to change the rpb_newdocument to rappanelbar1 when i copied and pasted the code here.

but yes, it does get the data and post it back to the grid, the problem is i can't get the page to change correctly. however, i was able to find a post that helped me. in the code below I now have to add "e.cancel=true" for the page index changed to work correctly.
Protected Sub RadGrid1_PageIndexChanged(sender As Object, e As GridPageChangedEventArgs)
    Dim RadGrid1 As RadGrid = DirectCast(RPB_NewDocument.FindItemByValue("New").FindControl("RadGrid1"), RadGrid)
    radgrid1.datasource=getdate()
    radgrid1.databind()
end sub

on second note, i now can't do the same for pagesizechanged. it keeps looping and eventually crashed. do you have any idea Princy? thanks
0
Princy
Top achievements
Rank 1
answered on 14 Jun 2013, 07:04 AM
Hi Duy,

I'm not sure what is causing this problem,cause this works fine at my side,please try if this helps.

VB:
Protected Sub RadGrid1_PageSizeChanged(source As Object, e As GridPageSizeChangedEventArgs)
    Dim RadGrid1 As RadGrid = DirectCast(RadPanelBar1.FindItemByValue("New").FindControl("RadGrid1"), RadGrid)
    RadGrid1.CurrentPageIndex = e.NewPageSize
    RadGrid1.DataBind()
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Duy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Duy
Top achievements
Rank 1
Share this question
or