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

[Solved] Paging not working

5 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sharon
Top achievements
Rank 1
Sharon asked on 08 Jun 2009, 10:05 AM
I have a RadGrid whose datasource is set dynamically. I have set paging to true but once I click the next page my grid disappers, but  appears  again with the page selected once my tabchange event is fired twice. My grid gets populates based on the hierarchical tab thats selected. I have rebound my grid in pageindexchanged, but still my grid disappears....

I have placed the decalration of my grid below....

<telerik:RadGrid ID="RadGrid1" runat="server" OnDataBound="RadGrid1_DataBound" GridLines="None" OnItemCommand="RadGrid1_ItemCommand"
         OnItemDataBound="RadGrid1_ItemDataBound" ShowHeader="false" OnItemCreated="RadGrid1_ItemCreated" AllowPaging="true" PageSize="6"
          OnPageIndexChanged="RadGrid1_PageIndexChanged">
    <MasterTableView TableLayout="Fixed" DataKeyNames="id">               
        <ItemTemplate>            
            <%# (((GridItem)Container).ItemIndex != 0)? "</td></tr></table>" : "" %>
                    <asp:Panel ID="ItemContainer" CssClass='<%# (((GridItem)Container).ItemType == GridItemType.Item)? "item" : "alternatingItem" %>'
                        runat="server">
                        <table cellpadding="0" cellspacing="0" border="0">
                            <tr valign="top">
                                <td>
                                    <asp:ImageButton ID="thumbimage" runat="server" ImageUrl='<%# Bind("imagepath") %>' OnClientClick=<%# "javascript:player.sendEvent('LOAD','" + Eval("filepath") +"')" %> />
                                </td>
                                <td>
                                    <asp:LinkButton ID="titlelinktab" runat="server" Text='<%# Bind("title") %>' OnClientClick=<%# "javascript:player.sendEvent('LOAD','" + Eval("filepath") +"')" %> ></asp:LinkButton><br />
                                    <asp:LinkButton ID="downloadbutton" runat="server" Text="Download" CommandName="download" CommandArgument='<%#Eval("id")%>' /><br />
                                    <asp:LinkButton ID="addbutton" runat="server" CommandName="addtoplaylist" CommandArgument='<%#Eval("id")%>'
                                         Text="Add to Playlist" />
                                </td>
                            </tr>
                        </table>                                                
                    </asp:Panel>
        </ItemTemplate>
    </MasterTableView>
    </telerik:RadGrid>

This is how I bind my grid initially,

protected void populategrid(string language, string category, string subcategory)
    {
        SqlConnection conn;
        SqlCommand comm;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myconn"].ConnectionString);
        comm = new SqlCommand("select id,title,subject_name,category,subcategory,language,filepath,imagepath from video " +
                "where ((category=@category and language=@language and subcategory=@subcategory) and publishdate <= getdate())", conn);

        comm.Parameters.Add("@category", SqlDbType.NVarChar, 20);
        comm.Parameters["@category"].Value = category;
        comm.Parameters.Add("@language", SqlDbType.NVarChar, 20);
        comm.Parameters["@language"].Value = language;
        comm.Parameters.Add("@subcategory", SqlDbType.NVarChar, 20);
        comm.Parameters["@subcategory"].Value = subcategory;

        conn.Open();
        //OleDbDataReader reader = comm.ExecuteReader();
        SqlDataReader reader = comm.ExecuteReader();
        if (reader.HasRows)
        {

            RadGrid1.DataSource = reader;
            RadGrid1.DataBind();
        }
        else
        {
            result.Text = "There are no records to be displayed in this category";           
        }      
     }

This is my pageindexchanged event

protected void RadGrid1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
    {
        RadGrid1.CurrentPageIndex = e.NewPageIndex;
       this.RadGrid1.Rebind();
  }

5 Answers, 1 is accepted

Sort by
0
Accepted
Pavlina
Telerik team
answered on 08 Jun 2009, 12:20 PM
Hello Sharon,

Simple data-binding through the DataBind() method can be used in simple scenarios which do not require the grid to perform complex operations such as paging. I suggest you switch to advanced binding with NeedDataSource event handling to see whether this helps.

All the best,

Pavlina
the Telerik team

 


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sharon
Top achievements
Rank 1
answered on 08 Jun 2009, 03:37 PM
Hi Pavlina ,
Thanks a lot for your immediate reply, I'm binding my grid dynamically, so I've no clue on how to use the needdatasource event. Could you please help me on this.

Thanking u once again.
0
Pavlina
Telerik team
answered on 08 Jun 2009, 04:30 PM
Hi Sharon,

For more information about Advanced Data-binding (using NeedDataSource event), please refer to this help article.

If you continue to experience difficulties, please open a formal support ticket and send us a simple runnable application with reproduced this erroneous behavior. Thus I could help you to find a quick solution/fix of this problem.

Sincerely yours,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sharon
Top achievements
Rank 1
answered on 09 Jun 2009, 08:57 AM
Hi Pavlina,
Thanks a lot for your reply. I got my grid working along with the paging feature. Your reply saved my day, thanks a lot once again.

Keep up your good work
Sharon Johnson
0
Pavlina
Telerik team
answered on 09 Jun 2009, 10:01 AM
Hello Sharon,

I am happy to hear that the provided information helped you to solve the problem.
Do not hesitate to write if any issues arise.

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Sharon
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Sharon
Top achievements
Rank 1
Share this question
or