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

GridView Pagging

6 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
A.mass
Top achievements
Rank 1
A.mass asked on 16 Apr 2009, 10:28 AM


Hello Telerik team,

I have a question regarding Rad Grid
I couldn't find any example on how to do paging if the grid isn't using the SqlDataSource control !!!
I'm binding data to my Rad Grid manually [ defining connection, command, and calling a stored procedure then bind the value to it ]
the problem I'm facing is that I don't know how to implement paging.

Any example or hint would be highly appreciated.

Best regards,

6 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 16 Apr 2009, 11:37 AM
Hi,

Try setting the AllowPaging property to true and set the PageSize to desired value.
Simple Data Binding



Shinu
0
A.mass
Top achievements
Rank 1
answered on 17 Apr 2009, 01:46 AM


Thanks a lot Mr. Shinu for your reply
Please, check my grid's code and tell me whats I'm doing wrong ?!

<telerik:RadGrid ID="gridMyLink" runat="server" AllowPaging="True"  
                                    AutoGenerateColumns="False" GridLines="None" PageSize="5"  
                                    onpageindexchanged="gridMyLink_PageIndexChanged" ShowHeader="False"
                                    <MasterTableView DataKeyNames="linkID"
                                        <RowIndicatorColumn Visible="False"
                                            <HeaderStyle Width="20px" /> 
                                        </RowIndicatorColumn> 
                                        <ExpandCollapseColumn Resizable="False" Visible="False"
                                            <HeaderStyle Width="20px" /> 
                                        </ExpandCollapseColumn> 
                                        <Columns> 
                                            <telerik:GridTemplateColumn UniqueName="TemplateColumn"
                                                <ItemTemplate> 
                                                    <asp:LinkButton ID="LinkButton2" runat="server"  
                                                        CommandArgument="<%#Bind('linkID') %>" PostBackUrl="<%#Bind('link') %>"  
                                                        Text="<%#Bind('linkName') %>"></asp:LinkButton> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                        </Columns> 
                                        <EditFormSettings> 
                                            <PopUpSettings ScrollBars="None" /> 
                                        </EditFormSettings> 
                                    </MasterTableView> 
                                </telerik:RadGrid> 

the code-behind code contains just the normal data binding placed whethen if(!Page.isPostBack) block.

Thanks again for your help.


0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Apr 2009, 05:38 AM
Hi Abdulla,

Setting the AllowPaging and PageSize property  is what is needed to implement Paging in Grid. So Paging must work with your Grid since you have set these properties. Can you confirm whether stored procedure returns enough records( greater than the PageSize set).

Shinu
0
A.mass
Top achievements
Rank 1
answered on 17 Apr 2009, 11:30 AM



Hello Mr. Shinu

I solved the problem, but in another way.
The way Rad Grid works in paging isn't like the one used with the normal grid [ provided by Visual Studio ].

to resolve it I did the following :
    private void generateMyLinks() 
    { 
        if (Session["dtMyLinks"] == null
        { 
            Session["dtMyLinks"] = LinksManager.getLinks("test""choosen"); 
            gridMyLinks.DataSource = (DataTable)Session["dtMyLinks"]; 
            gridMyLinks.DataBind(); 
        } 
        else 
        { 
            gridMyLinks.DataSource = (DataTable)Session["dtMyLinks"]; 
            gridMyLinks.DataBind(); 
        } 
    } 

- I call this method @ every Page_Load
- Then I have my PageIndexChanged like the following:
    protected void gridMyLink_PageIndexChanged(object source, GridPageChangedEventArgs e) 
    { 
        gridMyLinks.CurrentPageIndex = e.NewPageIndex; 
    } 

I don't know if its the right approach to follow, if not please advice for a better one.

*** Another question regarding paging, is the slider works the same way ?! cuz when I tried it and click the new page its getting back to the 1st one.

Thanks a lot for your time & support,
Best Regards



0
Accepted
Princy
Top achievements
Rank 2
answered on 17 Apr 2009, 12:09 PM
Hello Abdulla,
 
Since you are using SimpleDataBinding techniques you would have to bind the grid after setting the CurrentPageIndex as shown below:
c#:
protected void gridMyLink_PageIndexChanged(object source, GridPageChangedEventArgs e)   
    {   
        gridMyLinks.CurrentPageIndex = e.NewPageIndex;   
        generateMyLinks();  
    }  

-Princy.
0
A.mass
Top achievements
Rank 1
answered on 17 Apr 2009, 01:25 PM


Hello Princy,

Thanks a lot for your suggestion, the previously written code worked fine, but its not working with the slider.
is there anyway to let the slider work ?!


Regards,
Tags
Grid
Asked by
A.mass
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
A.mass
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or